1602液晶显示记一日的计时
单片机源程序如下:
- #include <REGX52.H>
- #include <INTRINS.H>
- void delayms(unsigned char xms)
- {
- unsigned char i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
- }
- void showTime();
- void timer0(void );
- unsigned char COUNT = 0;
- unsigned char h1 = 2;
- unsigned char h2 = 3;
- unsigned char m1 = 5;
- unsigned char m2 = 9;
- unsigned char s1 = 5;
- unsigned char s2 = 0;
- unsigned char code table[]={
- "0123456789"};
- #include <1602.H>
- #include <1302.H>
- void main()
- {
- Lcd_Int();
-
- TMOD = 0x01;
- TL0 = (65536 - 50000)%256;
- TH0 = (65536 - 50000)/256;
- IE = 0x00;
- TR0 = 1;
- COUNT = 0x14;
-
- while(1)
- {
- if (TF0) {
- timer0();
- TF0 = 0;
- }
- }
- }
- void jishi() {
- writelcd(7,2,table[h1]);
- writelcd(8,2,table[h2]);
- writelcd(10,2,table[m1]);
- writelcd(11,2,table[m2]);
- writelcd(13,2,table[s1]);
- writelcd(14,2,table[s2]);
- writelcd(9,2,' ');writelcd(12,2,' ');
- writelcd(9,2,':');writelcd(12,2,':');
- }
- void timer0(void ) {
- TL0 = (65536 - 50000)%256;
- TH0 = (65536 - 50000)/256;
- switch(COUNT) {
- case 0:{
- //showTime();
- s2 ++;
-
- //秒
- if (s2 > 9) {
- s2=0;
- s1++;
- }
- if (s1 > 5) {
- s1 = 0;
- m2++;
- }
- //分
- if (m2 > 9) {
- m2=0;
- m1++;
- }
- if (m1 > 5) {
- m1 = 0;
- h2++;
- }
- //时
- if (h2 > 9)
- h1++;
- if ( h2 >3 && h1 == 2 ) {
- h2=0;
- h1=0;
- }
- if (h1 > 2) {
- h1 = 0;
-
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
1602液晶显示记一日的计时.zip
(65.29 KB, 下载次数: 9)
|