错误太多:主要是抄写错误,错用大小写等等。
给你改了,对比一下就知道哪里错了。
自动打铃系统.c
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define KSET 0xe0
- #define KSET_LONG 0xe1
- #define KINC 0xd0
- #define KDEC 0xb0
- #define KDOWN 0x70
- #define AT24C02 0xa0
- #define DS1307 0xD0
- extern bit ISendStr(uchar sla,uchar suba,uchar*s,uchar no);
- extern bit IRcvStr(uchar sla,uchar suba,uchar*s,uchar no);
- extern void LCD_DispIni(void);
- extern void LCD_DispFill(uchar filldata);
- extern void LCD_DispChar(bit color,uchar cy,uchar cx,char dispdata);
- extern void LCD_DispStr(bit color,uchar cy,uchar cx,char*disp_str);
- extern void LCD_DispHZ(uchar cy,uchar cx,char dispdata);
- extern void LCD_DispHZStr(uchar cy,uchar cx,char*disp_str);
- sbit SOUND=P3^6;
- uchar hzmsg[7]={0,1,2,3,4,5,0xff};
- uchar idata alatime[16][2]={{ 6,00},{ 6,46},{ 6,47},{ 6,48},
- {10,05},{10,45},{11,40},{13,30},
- {14,10},{14,50},{15,20},{16,00},
- {16,40},{17,20},{19,30},{21,00}};
- uchar max[3]={24,60,60};
- uchar time[3]={6,45,55};
- uchar idata sbuf[3];
- bit mk;
- void delay(uchar t)
- {
- uchar i;
- while(t--)
- for(i=0;i<250;i++);
- }
- uchar HexBcd(uchar hex)
- {
- return(((hex/10)<<4)|(hex%10));
- }
- uchar BcdHex(uchar bcd)
- {
- uchar hex,hex1;
- hex=bcd&0x0f;
- hex1=(bcd>>4)*10;
- return(hex+hex1);
- }
- uchar Locate(void)
- {
- uchar n;
- n=0;
- while(n<16)
- { if(time[0]<alatime[n][0])break;
- else if((time[0]==alatime[n][0])&&(time[1]<alatime[n][1]))break;
- n++;
- }
- if(n==16)n=0;
- return(n);
- }
- void LCD_DispDat(bit color,uchar cy,uchar cx,char dat)
- {
- uchar str[3];
- str[0]=dat/10+0x30;
- str[1]=dat%10+0x30;
- str[2]=0;
- LCD_DispStr(color,cy,cx,str);
- }
- uchar GetKey(void)
- {
- uchar key;
- uchar t;
- if((key=P2&0xf0)==0xf0)return 0xff;
- for(t=0;t<5;t++)delay(5);
- if((key=P2&0xf0)==0xf0)return 0xff;
- while((P2&0xf0)!=0xf0)
- { delay(5);
- if(t<250)t++;
- }
- if((t>100)&&(key==0xE0))
- return 0xE1;
- return key;
- }
- void DispTime(void)
- {
- LCD_DispDat(0,2,4,time[0]);
- LCD_DispChar(0,2,6,':');
- LCD_DispDat(0,2,7,time[1]);
- LCD_DispChar(0,2,9,':');
- LCD_DispDat(0,2,10,time[2]);
- }
- void DispAla(bit color,uchar no)
- {
- LCD_DispDat(color,4+no%4,8,alatime[no][0]);
- LCD_DispChar(color,4+no%4,10,':');
- LCD_DispDat(color,4+no%4,11,alatime[no][1]);
- }
- void DispPage(uchar page)
- {
- uchar i;
- for(i=0;i<4;i++)
- { LCD_DispChar(0,4+i,3,'(');
- LCD_DispDat(0,4+i,4,page*4+i+1);
- LCD_DispChar(0,4+i,6,')');
- DispAla(0,page*4+i);
- }
- }
- void ReadTime(void)
- {
- IRcvStr(DS1307,0x00,sbuf,3);
- time[0]=BcdHex(sbuf[2]&0x3f);
- time[1]=BcdHex(sbuf[1]&0x7f);
- time[2]=BcdHex(sbuf[0]&0x7f);
- }
- void SetTime(void)
- {
- sbuf[0]=HexBcd(time[2]);
- sbuf[1]=HexBcd(time[1]);
- sbuf[2]=HexBcd(time[0]);
- ISendStr(DS1307,0x00,sbuf,3);
- }
- void EditTime(void)
- { uchar col=0;
- uchar k;
- ReadTime();
- DispTime();
- LCD_DispDat(1,2,4,time[col]);
- while(1)
- { k=GetKey();
- if(k==KINC)
- { time[col]++;
- if(time[col]==max[col])
- time[col]=0;
- LCD_DispDat(1,2,4+col*3,time[col]);
- }
- else if(k==KDEC)
- { time[col]--;
- if(time[col]==0xff)
- time[col]=max[col]-1;
- LCD_DispDat(1,2,4+col*3,time[col]);
- }
- else if(k==KSET)
- { LCD_DispDat(0,2,4+col*3,time[col]);
- col=(col+1)%0x03;
- LCD_DispDat(1,2,4+col*3,time[col]);
- }
- else if(k==KSET_LONG)
- { LCD_DispDat(0,2,4+col*3,time[col]);
- SetTime();
- break;
- }
- }
- }
- void EditAla(void)
- { uchar no=0;
- uchar col=0;
- uchar k;
- DispPage(0);
- LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
- while(1)
- { k=GetKey();
- if(k==KINC)
- { alatime[no][col]++;
- if(alatime[no][col]==max[col])
- alatime[no][col]=0;
- LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
- }
- else if(k==KDEC)
- { alatime[no][col]--;
- if(alatime[no][col]==0xff)
- alatime[no][col]=max[col]-1;
- LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
- }
- else if(k==KSET)
- { LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
- col=(col+1)%0x01;
- LCD_DispDat(1,4+(no%4),8+col*3,alatime[no][col]);
- }
- else if(k==KDOWN)
- { LCD_DispDat(0,4+(no%4),8+col*3,alatime[no][col]);
- no++;
- col=0;
- if(no==16)no=0;
- if(no%4==0)
- DispPage(no/4);
- LCD_DispDat(1,4+(no%4),8,alatime[no][col]);
- }
- else if(k==KSET_LONG)
- { for(no=0;no<4;no++)
- { ISendStr(AT24C02,no*8,&alatime[no*4][0],8);
- delay(20);
- }
- no=0x55;
- ISendStr(AT24C02,0xff,&no,1);
- break;
- }
- }
- }
- void main(void)
- {
- uchar i;
- uchar k;
- mk=0;
- TMOD=0x01;
- TH0=-1000/256;
- TL0=-1000%256;
- ET0=1;
- EA=1;
- IT0=1;
- EX0=1;
- LCD_DispIni();
- LCD_DispHZStr(0,1,hzmsg);
- DispTime();
- IRcvStr(AT24C02,0xff,&i,1);
- if(i==0x55)
- IRcvStr(AT24C02,0x00,&alatime[0][0],32);
- SetTime();
- sbuf[0]=0x10;
- ISendStr(DS1307,0x07,sbuf,0x01);
- delay(20);
- i=Locate();
- DispPage(i/4);
- DispAla(1,i);
- while(1)
- {
- k=GetKey();
- if(k==KSET)
- { EditTime();
- i=Locate();
- DispPage(i/4);
- DispAla(1,i);
- }
- else if(k==KSET_LONG)
- { EditAla();
- i=Locate();
- DispPage(i/4);
- DispAla(1,i);
- }
- if(mk==1)
- { ReadTime();
- mk=0;
- DispTime();
- if(time[2]==0)
- { if((time[1]==alatime[i][1])&&(time[0]==alatime[i][0]))
- { DispAla(0,i);
- i++;
- if(i==16)i=0;
- if(i%4==0)
- DispPage(i/4);
- DispAla(1,i);
- TR0=1;
- }
- }
- }
- }
- }
- void int0(void)interrupt 0
- {
- mk=1;
- }
- void timer0(void)interrupt 1
- {
- static uchar n=0;
- static uchar m=0;
- TH0=-1000/256;
- TL0=-1000%256;
- n++;
- if(n==200)
- { n=0;
- m++;
- if(m==100)
- { m=0;
- TR0=0;
- SOUND=0;
- }
- }
- if(m%4==0)
- SOUND=~SOUND;
- else
- SOUND=1;
- }
复制代码
LCD12864IO.c
- #include <reg51.h>
- #include <absacc.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit LCD_RST=P1^0;
- sbit DI=P1^5;
- sbit RW=P1^4;
- sbit CS1=P1^2;
- sbit CS2=P1^1;
- sbit EN=P1^3;
- sbit RDY=P0^7;
- sfr LCD=0x80;
- #define LCD_DISPON 0x3f
- #define LCD_STARTROW 0xc0
- #define LCD_ADDRSTRY 0xb8
- #define LCD_ADDRSTRX 0x40
- #define P_CS1 0
- #define P_CS2 1
- uchar code ASCII_TAB[480] =
- { 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x9e, 0x00, 0x00,
- 0x00, 0x0e, 0x00, 0x0e, 0x00,
- 0x28, 0xfe, 0x28, 0xfe, 0x28,
- 0x48, 0x54, 0xfe, 0x54, 0x24,
- 0x46, 0x26, 0x10, 0xc8, 0xc4,
- 0x6c, 0x92, 0xaa, 0x44, 0xa0,
- 0x00, 0x0a, 0x06, 0x00, 0x00,
- 0x00, 0x38, 0x44, 0x82, 0x00,
- 0x00, 0x82, 0x44, 0x38, 0x00,
- 0x28, 0x10, 0x7c, 0x10, 0x28,
- 0x10, 0x10, 0x7c, 0x10, 0x10,
- 0x00, 0xa0, 0x60, 0x00, 0x00,
- 0x10, 0x10, 0x10, 0x10, 0x10,
- 0x00, 0xc0, 0xc0, 0x00, 0x00,
- 0x40, 0x20, 0x10, 0x08, 0x04,
- 0x7C, 0xA2, 0x92, 0x8A, 0x7C,
- 0x84, 0xC2, 0xA2, 0x92, 0x8C,
- 0x42, 0x82, 0x8A, 0x96, 0x62,
- 0x30, 0x28, 0x24, 0xFE, 0x20,
- 0x4E, 0x8A, 0x8A, 0x8A, 0x72,
- 0x78, 0x94, 0x92, 0x92, 0x60,
- 0x02, 0xE2, 0x12, 0x0A, 0x06,
- 0x6C, 0x92, 0x92, 0x92, 0x6C,
- 0x0C, 0x92, 0x92, 0x52, 0x3C,
- 0x00, 0x6C, 0x6C, 0x00, 0x00,
- 0x00, 0xAC, 0x6C, 0x00, 0x00,
- 0x10, 0x28, 0x44, 0x82, 0x00,
- 0x28, 0x28, 0x28, 0x28, 0x28,
- 0x00, 0x82, 0x44, 0x28, 0x10,
- 0x04, 0x02, 0xA2, 0x12, 0x0C,
- 0x64, 0x92, 0xF2, 0x82, 0x7C,
- 0xFC, 0x22, 0x22, 0x22, 0xFC,
- 0xFE, 0x92, 0x92, 0x92, 0x6C,
- 0x7C, 0x82, 0x82, 0x82, 0x44,
- 0xFE, 0x82, 0x82, 0x44, 0x38,
- 0xFE, 0x92, 0x92, 0x92, 0x82,
- 0xFE, 0x12, 0x12, 0x12, 0x02,
- 0x7C, 0x82, 0x92, 0x92, 0xF4,
- 0xFE, 0x10, 0x10, 0x10, 0xFE,
- 0x00, 0x82, 0xFE, 0x82, 0x00,
- 0x40, 0x80, 0x82, 0x7E, 0x02,
- 0xFE, 0x10, 0x28, 0x44, 0x82,
- 0xFE, 0x80, 0x80, 0x80, 0x80,
- 0xFE, 0x04, 0x18, 0x04, 0xFE,
- 0xFE, 0x08, 0x10, 0x20, 0xFE,
- 0x7C, 0x82, 0x82, 0x82, 0x7C,
- 0xFE, 0x12, 0x12, 0x12, 0x0C,
- 0x7C, 0x82, 0xA2, 0x42, 0xBC,
- 0xFE, 0x12, 0x32, 0x52, 0x8C,
- 0x8C, 0x92, 0x92, 0x92, 0x62,
- 0x02, 0x02, 0xFE, 0x02, 0x02,
- 0x7E, 0x80, 0x80, 0x80, 0x7E,
- 0x3E, 0x40, 0x80, 0x40, 0x3E,
- 0x7E, 0x80, 0x70, 0x80, 0x7E,
- 0xC6, 0x28, 0x10, 0x28, 0xC6,
- 0x0E, 0x10, 0xE0, 0x10, 0x0E,
- 0xC2, 0xA2, 0x92, 0x8A, 0x86,
- 0x00, 0xFE, 0x82, 0x82, 0x00,
- 0x04, 0x08, 0x10, 0x20, 0x40,
- 0x00, 0x82, 0x82, 0xFE, 0x00,
- 0x08, 0x04, 0x02, 0x04, 0x08,
- 0x80, 0x80, 0x80, 0x80, 0x80,
- 0x00, 0x02, 0x04, 0x08, 0x00,
- 0x40, 0xA8, 0xA8, 0xA8, 0xF0,
- 0xFE, 0x90, 0x88, 0x88, 0x70,
- 0x70, 0x88, 0x88, 0x88, 0x40,
- 0x70, 0x88, 0x88, 0x90, 0xFE,
- 0x70, 0xA8, 0xA8, 0xA8, 0x30,
- 0x10, 0xFC, 0x12, 0x02, 0x04,
- 0x18, 0xA4, 0xA4, 0xA4, 0x7C,
- 0xFE, 0x10, 0x08, 0x08, 0xF0,
- 0x00, 0x88, 0xFA, 0x80, 0x00,
- 0x40, 0x80, 0x88, 0x7A, 0x00,
- 0xFE, 0x20, 0x50, 0x88, 0x00,
- 0x00, 0x82, 0xFE, 0x80, 0x00,
- 0xF8, 0x08, 0x30, 0x08, 0xF8,
- 0xF8, 0x10, 0x08, 0x08, 0xF0,
- 0x70, 0x88, 0x88, 0x88, 0x70,
- 0xF8, 0x28, 0x28, 0x28, 0x10,
- 0x10, 0x28, 0x28, 0x30, 0xF8,
- 0xF8, 0x10, 0x08, 0x08, 0x10,
- 0x90, 0xA8, 0xA8, 0xA8, 0x40,
- 0x08, 0x7E, 0x88, 0x80, 0x40,
- 0x78, 0x80, 0x80, 0x40, 0xF8,
- 0x38, 0x40, 0x80, 0x40, 0x38,
- 0x78, 0x80, 0x60, 0x80, 0x78,
- 0x88, 0x50, 0x20, 0x50, 0x88,
- 0x18, 0xA0, 0xA0, 0xA0, 0x78,
- 0x88, 0xC8, 0xA8, 0x98, 0x88,
- 0x00, 0x10, 0x6C, 0x82, 0x00,
- 0x00, 0x00, 0xFE, 0x00, 0x00,
- 0x00, 0x82, 0x6C, 0x10, 0x00,
- 0x10, 0x10, 0x54, 0x38, 0x10,
- 0x10, 0x38, 0x54, 0x10, 0x10};
- uchar code HZTAB[480] = {0}; //?????
- void LCD_WrCmd(bit port,uchar cmd)
- { EN=0;
- if(port)
- {
- CS2=1;
- CS1=0;
- }
- else
- {
- CS2=0;
- CS1=1;
- }
- DI=0;
- RW=0;
- EN=1;
- LCD=cmd;
- EN=0;
- }
- void LCD_WrDat(bit port,uchar wrdata)
- { EN=0;
- if(port)
- {
- CS2=1;
- CS1=0;
- }
- else
- {
- CS2=0;
- CS1=1;
- }
- DI=1;
- RW=0;
- EN=1;
- LCD=wrdata;
- EN=0;
- }
- void LCD_DispFill(uchar filldata)
- { uchar x,y;
- LCD_WrCmd(P_CS1,LCD_STARTROW);
- LCD_WrCmd(P_CS2,LCD_STARTROW);
- for(y=0;y<8;y++)
- { LCD_WrCmd(P_CS1,LCD_ADDRSTRY+y);
- LCD_WrCmd(P_CS1,LCD_ADDRSTRX);
- LCD_WrCmd(P_CS2,LCD_ADDRSTRY+y);
- LCD_WrCmd(P_CS2,LCD_ADDRSTRX);
- for(x=0;x<64;x++)
- {
- LCD_WrDat(P_CS1,filldata);
- LCD_WrDat(P_CS2,filldata);
- }
- }
- }
- void LCD_DispIni(void)
- { uint i;
- LCD_RST=0;
- for(i=0;i<500;i++);
- LCD_RST=1;
- LCD_WrCmd(P_CS1,LCD_DISPON);
- LCD_WrCmd(P_CS1,LCD_STARTROW);
- LCD_WrCmd(P_CS2,LCD_DISPON);
- LCD_WrCmd(P_CS2,LCD_STARTROW);
- LCD_DispFill(00);
- LCD_WrCmd(P_CS1,LCD_ADDRSTRY+0);
- LCD_WrCmd(P_CS1,LCD_ADDRSTRX+0);
- LCD_WrCmd(P_CS2,LCD_ADDRSTRY+0);
- LCD_WrCmd(P_CS2,LCD_ADDRSTRX+0);
- }
- void LCD_DispChar(bit color,uchar cy,uchar cx,char dispdata)
- { uchar *pch;
- uchar i;
- bit port;
- cy=cy&0x07;
- cx=cx&0x0f;
- pch=&ASCII_TAB[(dispdata-0X20)*5];
- if((cx&0x08)==0)
- {
- port=P_CS1;
- i=cx<<3;
- }
- else
- { port=P_CS2;
- i=(cx&0x07)<<3;
- }
- LCD_WrCmd(port,LCD_ADDRSTRX+i);
- LCD_WrCmd(port,LCD_ADDRSTRY+cy);
- for(i=0;i<5;i++);
- if(color==0)
- LCD_WrDat(port,0x00);
- else
- LCD_WrDat(port,0xff);
- for(i=0;i<5;i++)
- {if(color==0)
- LCD_WrDat(port,*pch);
- else
- LCD_WrDat(port,~*pch);
- pch++;
- }
- if(color==0)
- LCD_WrDat(port,0x00);
- else
- LCD_WrDat(port,0xff);
- for(i=0;i<5;i++)
- if(color==0)
- LCD_WrDat(port,0x00);
- else
- LCD_WrDat(port,0xff);
- }
- void LCD_DispStr(bit color,uchar cy,uchar cx,char*disp_str)
- { while(*disp_str!='\0')
- {
- cy=cy&0x07;
- cx=cx&0x0f;
- LCD_DispChar(color,cy,cx,*disp_str);
- disp_str++;
- cx++;
- if(cx>15)cy++;
- }
- }
- void LCD_DispHZ(uchar cy, uchar cx, char dispdata)
- {
- uchar *pdat;
- uchar i,s,page;
- bit port;
- cy=cy&0x03;
- cx=cx&0x07;
- pdat=&HZTAB[dispdata*32];
- if((cx&0x04)==0)
- {
- port=0;
- s=cx<<4;
- }
- else
- {
- port=1;
- s=(cx<<4)-64;
- }
- for(page=0;page<2;page++)
- { LCD_WrCmd(port,LCD_ADDRSTRX+s);
- LCD_WrCmd(port,LCD_ADDRSTRY+(cy<<1)+page);
- for(i=0;i<5;i++);
- for(i=0;i<16;i++)
- { LCD_WrDat(port,*pdat);
- pdat++;
- }
- for(i=0;i<5;i++);
- }
- }
- void LCD_DispHZStr(uchar cy,uchar cx,char*disp_str)
- { while(*disp_str!=0xff)
- {
- cy=cy&0x03;
- cx=cx&0x07;
- LCD_DispHZ(cy,cx,*disp_str);
- disp_str++;
- cx++;
- if(cx>7)
- {cy++;
- cx=0;
- }
- }
- }
复制代码
I2C.c
|