1、单片机通过串口通信调整时间的程序单片机通过串口通信调整时间的程序 本程序所用的原理图下载: 点这里 ,单片机芯片使用的stc89c51;找到时钟部分的原理图修改为你自己的电路上的io即可.这是一整个单片机开发板的电路图其他的忽略. /*通过串口通信调整时间*/*功能:单片机开始上电时点阵显示倒计时3,2,1,0,然后点阵LED关闭显示* 定时器和串口开始工作,定时器开始一秒计时,并在数码管上显示时,分,秒 * 此计时器可以通过串口发送数据调整时间,可调整时与分,当调整分钟时秒清零 * 附加功能:当单片机收到数据时有蜂鸣器响一声作为提示 * 彩色流水灯以20毫秒的速度向左流动 *作者:徐冉*日期
2、:2013-06-15-09:15 - 12:10*备注:程序已经顺利通过调试*/*51hei开发板*/*AT89C52-RC MCU*/#include ;typedef unsigned int uint;typedef unsigned char uchar;sbit wela = P27;sbit dula = P26;sbit FM = P23;sbit din = P20;sbit cs = P21;sbit clk = P22;/*点阵LED显示取模编码表*/uchar code dis8 = 0x00,0x3E,0x02,0x02,0x3E,0x02,0x02,0x3E,/3
3、0x00,0x3E,0x02,0x02,0x3E,0x20,0x20,0x3E,/2 0x00,0x18,0x38,0x08,0x08,0x08,0x08,0x3E,/1 0x00,0x3C,0x24,0x24,0x24,0x24,0x24,0x3C,/0 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00/关闭显示 ; /*数码管显示编码表*/uchar code table = 0x3F, /"0" 0x06, /"1" 0x5B, /"2" 0x4F, /"3" 0x66, /&q
4、uot;4" 0x6D, /"5" 0x7D, /"6" 0x07, /"7" 0x7F, /"8" 0x6F /"9" ; uchar shi = 0, fen = 0, miao = 0, counter = 0, flag = 0, j = 0; /*点阵LED-MAX7219*/*写字节*/void write_byte(uchar date)uchar i = 0;cs = 0;for(i = 0; i ; 0; x-) for(y = 110; y ; 0; y-); /*
5、串口和定时器T0初始化*/void init()TMOD = 0x21;/T1工作方式2,T0工作方式1TH0 = 0xB8;TL0 = 0x00;TH1 = 0xFA;TL1 = 0xFA;TR1 = 1;SM0 = 0;SM1 = 1;REN = 1;EA = 1;ES = 1;ET0 = 1;/*数码管显示时间*/void display(uchar shi, uchar fen, uchar miao)uchar shi_s, shi_g;uchar fen_s, fen_g;uchar miao_s, miao_g;shi_s = shi / 10 % 10;shi_g = shi
6、% 10;fen_s = fen / 10 % 10;fen_g = fen % 10;miao_s = miao / 10 % 10;miao_g = miao % 10;dula = 1;P0 = tableshi_s;dula = 0;P0 = 0xff;wela = 1;P0 = 0xfe;wela = 0;P0 = 0x00;delayms(1);dula = 1;P0 = tableshi_g;dula = 0;P0 = 0xff;wela = 1;P0 = 0xfd;wela = 0;P0 = 0x00;delayms(1);dula = 1;P0 = tablefen_s;du
7、la = 0;P0 = 0xff;wela = 1;P0 = 0xfb;wela = 0;P0 = 0x00;delayms(1);dula = 1;P0 = tablefen_g;dula = 0;P0 = 0xff;wela = 1;P0 = 0xf7;wela = 0;P0 = 0x00;delayms(1);dula = 1;P0 = tablemiao_s;dula = 0;P0 = 0xff;wela = 1;P0 = 0xef;wela = 0;P0 = 0x00;delayms(1);dula = 1;P0 = tablemiao_g;dula = 0;P0 = 0xff;we
8、la = 1;P0 = 0xdf;wela = 0;P0 = 0x00;delayms(1);/*点阵显示程序*/void display_max7219()uchar m, n;for(m = 0; m ;= 8) j = 0; if(counter = 50) counter = 0; miao+; if(miao ;= 60) miao = 0; fen+; if(fen ;= 60) fen = 0; shi+; if(shi ;= 24) shi = 0; /*串口中断服务程序*/void uart_int() interrupt 4RI = 0;if(SBUF ;= 23 & SBUF ;= 0 & SBUF = 23) shi = SBUF; fen = SBUF; FM = 0; delayms(30); FM = 1; flag = 1;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1