带字库12864液晶显示DS1302数字时钟C源程序

51单片机+带字库液晶12864+DS1302数字时钟C源程序(无按键修改功能) 2009-10-19 16:47

经过两天的搜索与调试,在别人程序的基础上,不断修改,终于调试成功了这个程序。目前还不能修改时间与日期,只是以预定时间以始。

适用于开发板:51单片机(AT89S52)+带字库液晶12864(ST7920)+DS1302(实时时钟) 实现功能:简单,数字时钟+日期(以后会不断完美)。 C语言源程序如下:

#include #include

#define uchar unsigned char #define uint unsigned int

/*DS1302 端口设置 */

sbit SCK=P3^6; //DS1302时钟 sbit SDA=P3^4; //DS1302 IO sbit RST = P3^5; // DS1302复位

bit ReadRTC_Flag; //读DS1302全局变量

/* 12864端口定义*/

#define LCD_data P0 //带字库液晶12864数据口 sbit LCD_RS = P2^4; //寄存器选择输入 sbit LCD_RW = P2^5; //液晶读/写控制 sbit LCD_EN = P2^6; //液晶使能控制 sbit PSB=P2^1; //并口控制 sbit RES=P2^3;

uchar code dis1[] = {\电子设计天地\ //液晶显示的汉字 uchar code dis2[] = {\有志者,事竟成!\

uchar code dis4[] = {'0','1','2','3','4','5','6','7','8','9'}; unsigned char temp;

#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();}; void lcd_pos(uchar X,uchar Y); //确定显示位置

unsigned char l_tmpdate[7]={0,7,16,19,10,1,9};//秒分时日月周年09-10-19 16:07:00 code unsigned char write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位

code unsigned char read_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};

void Write_Ds1302_byte(unsigned char temp);

void Write_Ds1302( unsigned char address,unsigned char dat ); unsigned char Read_Ds1302 ( unsigned char address ); void Read_RTC(void);//read RTC void Set_RTC(void); //set RTC

void InitTIMER0(void);//inital timer0

/*******************************************************************/

/* */ /* 延时函

数 */

/* */

/*******************************************************************/ void delay(unsigned int m) //延时程序 { unsigned int i,j; for(i=0;i

for(j=0;j<10;j++);

}

/*******************************************************************/ /* */ /*检查LCD忙状

态 */

/*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 /* */

/*******************************************************************/ bit lcd_busy()

{ bit result; LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; delayNOP();

result = (bit)(P0&0x80); LCD_EN = 0;

*/

return(result); }

/*******************************************************************/

/* */ /*写指令数据到

LCD */

/*RS=L,RW=L,E=高脉冲,D0-D7=指令

码。 */

/* */

/*******************************************************************/ void lcd_wcmd(uchar cmd)

{ while(lcd_busy()); LCD_RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); P0 = cmd; delay(1); LCD_EN = 1; delay(1); LCD_EN = 0; }

/*******************************************************************/

/* */ /*写显示数据到

LCD */ /*RS=H,RW=L,E=高脉冲,D0-D7=数

据。 */

/* */

/*******************************************************************/ void lcd_wdat(uchar dat)

{ while(lcd_busy()); LCD_RS = 1; LCD_RW = 0; LCD_EN = 0;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4