_nop_(); DSIO = 0; _nop_(); DSIO = 1; _nop_(); return dat; }
void Ds1302Init() {
uchar n;
Ds1302Write(0x8E,0X00); for (n=0; n<7; n++) { Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]); }
Ds1302Write(0x8E,0x80); }
void Ds1302ReadTime() {
uchar n;
for (n=0; n<7; n++) { TIME[n] = Ds1302Read(READ_RTC_ADDR[n]); } }
void Ds1302Set() {
uchar TIME1[7] ; uchar n;
LCD12864_SetWindow(0, 0); Ds1302Write(0x8E,0X00); for (n=0; n<7; n++) { Ds1302Write(WRITE_RTC_ADDR[n],TIME1[n]); }
Ds1302Write(0x8E,0x80); } void Ds1302Init1() {
uchar n;
if(Ds1302Read(0xc1)!=0xaa)
26
{
Ds1302Write(0x8E,0X00); for (n=0; n<7; n++) {
Ds1302Write(WRITE_RTC_ADDR[n],TIME[n]); }
Ds1302Write(0xc0,0xaa); } }
lcd12864.c(LCD液晶显示)
#include\
uchar BitReverse32(uchar number) {
uchar res = 0; uint i;
for(i = 1; i <= 8; i++) {
res |= (number&1) << (8-i); number >>= 1; }
return res; }
void LCD12864_Delay1ms(uint c) {
uchar a,b; for(; c>0; c--) {
for(b=199; b>0; b--) {
for(a=1; a>0; a--); } } }
uchar LCD12864_Busy(void) {
uchar i = 0;
LCD12864_RS = 0;
27
LCD12864_RW = 1; LCD12864_EN = 1;
LCD12864_Delay1ms(1);
LCD12864_DATAPORT = BitReverse32(LCD12864_DATAPORT); while((LCD12864_DATAPORT & 0x80) == 0x80) { i++; if(i > 100) { LCD12864_EN = 0; return 0; } }
LCD12864_EN = 0;
return 1; }
void LCD12864_WriteCmd(uchar cmd) {
uchar i; i = 0;
while( LCD12864_Busy() == 0) { LCD12864_Delay1ms(1); i++; if( i>100) { return; } }
LCD12864_RS = 0; LCD12864_RW = 0; LCD12864_EN = 0;
LCD12864_DATAPORT = cmd;
LCD12864_DATAPORT = BitReverse32(LCD12864_DATAPORT); LCD12864_EN = 1; LCD12864_Delay1ms(5); LCD12864_EN = 0; }
28
void LCD12864_WriteData(uchar dat) {
uchar i; i = 0;
while( LCD12864_Busy() == 0) { LCD12864_Delay1ms(1); i++; if( i>100) { return; } }
LCD12864_RS = 1; LCD12864_RW = 0; LCD12864_EN = 0;
LCD12864_DATAPORT = dat;
LCD12864_DATAPORT = BitReverse32(LCD12864_DATAPORT); LCD12864_EN = 1; LCD12864_Delay1ms(5); LCD12864_EN = 0; }
#ifdef LCD12864_PICTURE
uchar LCD12864_ReadData(void) {
uchar i, readValue;
i = 0;
while( LCD12864_Busy() == 0) { LCD12864_Delay1ms(1); i++; if( i>100) { return 0; } }
LCD12864_RS = 1; LCD12864_RW = 1;
29
LCD12864_EN = 0;
LCD12864_Delay1ms(1);
LCD12864_EN = 1;
LCD12864_Delay1ms(1);
LCD12864_DATAPORT = BitReverse32(LCD12864_DATAPORT); readValue = LCD12864_DATAPORT; LCD12864_EN = 0;
return readValue; }
#endif
void LCD12864_Init() {
LCD12864_WriteCmd(0x30); LCD12864_WriteCmd(0x0c); LCD12864_WriteCmd(0x06); LCD12864_WriteCmd(0x01); }
void LCD12864_SetWindow(uchar x, uchar y) {
uchar pos;
if(x == 0) { x = 0x80; }
else if(x == 1) { x = 0x90; }
else if(x == 2) { x = 0x88; }
else if(x == 3) { x = 0x98;
30