#include#includevoid somenop(){ uchar i=5; while(i--) { _nop_(); }}//8位扫描显示,共阳数码管uchar shum[]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};void delaym(){ uchar i; for(i=0;i<0xff;i++); }void init();void star();void stop();void ack();void write_byte(uchar date);uchar read_byte();sbit scl=P1^2;sbit sda=P1^3;uchar sec,min=30,tt;void init(){ sda=1; somenop(); scl=1; somenop(); }void star(){ sda=1; somenop(); scl=1; somenop(); sda=0; somenop();}void stop(){ sda=0; somenop(); scl=1; somenop(); sda=1; somenop();}void ack(){ scl=1; somenop(); scl=0; somenop();}void write_byte(uchar date){ uchar i,temp; temp=date; for(i=0;i<8;i++) { scl=0; somenop(); if((temp&0x80)==0x80) { sda=1;} else { sda=0;} temp=temp<<1; somenop(); scl=1; somenop(); scl=0; somenop(); } scl=0; somenop(); sda=1; somenop();}uchar read_byte(){ uchar i,temp1,j; scl=0; somenop(); sda=1; somenop(); for(i=0;i<8;i++) { scl=1; somenop(); j=sda; temp1=(temp1<<1)|j; scl=0; somenop(); } return temp1;}void write_address(uchar address,uchar date){ star(); write_byte(0xa0); ack(); write_byte(address); ack(); write_byte(date); ack(); stop();}uchar read_address(uchar address){ uchar redata; star(); write_byte(0xa0); ack(); write_byte(address); ack(); star(); write_byte(0xa1); ack(); redata=read_byte(); stop(); return redata;}void timer0() interrupt 1{ TH0=(65536-50000)/256; TL0=(65536-50000)%256; tt++; if(tt==20) { tt=0; sec++; if(sec==60) {sec=0;min++; if(min==60) { min=0;} write_address(100,min); delaym(); } write_address(10,sec); delaym(); //把秒写入AT24C02的10地址 //单片机写数据会占用一些时间,所以延时一会儿较好 }}void int0(void) interrupt 0{ EA=0; min++; if(min==60) { min=0; } write_address(100,min); //把分写入AT24C02的100地址 delaym(); EA=1;}void disp(){ P0=shum[sec%10];//sec 个位 P2=0x08; delaym(); P0=shum[sec/10];//sec 十位 P2=0x04; delaym(); P0=shum[min%10]&0x7f; //加小数点 P2=0x02; delaym(); P0=shum[min/10]; P2=0x01; delaym();}void main(){ TMOD=0x01; ET0=1; EX0=1; IT0=1; EA=1; TH0=(65536-50000)/256; TL0=(65536-50000)%256; TR0=1; init(); sec=read_address(10); //从AT24C02的10地址读出秒数据 min=read_address(100);//从AT24C02的100地址读出分数据 while(1) { disp(); }}
导读:目前正在解读《51单片机IO口模拟驱动AT24c02》的相关信息,《51单片机IO口模拟驱动AT24c02》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《51单片机IO口模拟驱动AT24c02》的详细说明。
简介:本文给大家分享了一个51单片机IO口模拟驱动AT24c02源代码。
提醒:《51单片机IO口模拟驱动AT24c02》最后刷新时间 2024-03-14 00:58:00,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《51单片机IO口模拟驱动AT24c02》该内容的真实性请自行鉴别。