资源描述:
《堆栈设计 文本文档》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、堆栈设计文本文档#include#include#defineuintunsignedint#defineucharunsignedcharsbitscl=P3^6;sbitsda=P3^7;voidstart(void);voidstop(void);voidask(void);voidnoask(void);voidinit(void);voiddelay(void);voiddelay1(void);voidwrite_dat(uchardat);ucharread_dat(void);voiddela
2、y(void){uinta=6;while(a--);}voiddelay1(void){uinta=30000;while(a--);}voidstart(void)//开始数据传送{sda=1;delay();scl=1;delay();sda=0;delay();scl=0,//允许数据变化delay();}voidstop(void){sda=0;delay();scl=1;delay();sda=1;delay();}voidask(){uchari;scl=1;delay();while((sda==1)&&(i<100))i++;sc
3、l=0;delay();}voidnoask(void){sda=1;delay();scl=1;delay();scl=0;delay();}voidinit(){sda=1;scl=1;}voidwrite_dat(uchardat){uchari;scl=0;for(i=0;i<8;i++){if(dat&0x80){sda=1;}else{sda=0;}dat=dat<<1;delay();scl=1;delay();scl=0;delay();}sda=1;delay();}ucharread_dat(void){uchari;uchar
4、dat=0;scl=0;delay();sda=1;delay();for(i=0;i<8;i++){scl=1;delay();dat=dat<<1;if(sda){dat++;}scl=0;delay();}returndat;}voidmain(){init();start();write_dat(0xa0);ask();write_dat(10);ask();write_dat(0x55);ack();stop();///////////////////////////////////////////////////////////////
5、////////////#include#defineucharunsignedchar#defineuintunsignedintuintcnt=0;ucharsecond=0,minute=0,hour=0,year=2012,mounth=3,day=5;voiddelay(uintm){uinti;while(m--)for(i=10;i>0;i--);}voiddelay1(){uintn=500000;while(n--);}voiddisplay(uintnum,ucharoption){ucharcodetab[]
6、={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40};ucharw1,w2;w2=num/10;w1=num%10;switch(option){case0:{P2=(P2&0xfc)
7、0x00;P0=tab[w1];delay(10);P2=(P2&0xfc)
8、0x01;P0=tab[w2];delay(10);P2=(P2&0xfc)
9、0x02;P0=tab[10];delay();break;}case1:{P2=(P2&0xfc)
10、0x03;P0=tab[w1];delay(10
11、);P2=(P2&0xfc)
12、0x04;P0=tab[w2];delay(10);P2=(P2&0xfc)
13、0x05;P0=tab[10];delay();break;}case2:{P2=(P2&0xfc)
14、0x06;P0=tab[w1];delay(10);P2=(P2&0xfc)
15、0x07;P0=tab[w2];delay(10);break;}}}voidTimer0Init(){TMOD=0X01;TH0=64536/256;//产生1毫秒定时TL0=64536%256;EA=1;ET0=1;TR0=1;}voidmain(){Timer
16、0Init();while(1){display(second,0);display(minute,1);display(