51单片机—串口时钟
来源:互联网 发布:php .net哪个好 编辑:程序博客网 时间:2024/05/22 16:45
#include <reg52.h>#include "delay.h"#define SEGPORT P0#define uchar unsigned char sbit seg_select = P2^1;sbit bit_select = P2^0;sbit beep = P2^2;uchar segdata[16] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};uchar bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};uchar tempdata[8];uchar shi = 0;uchar fen = 1;uchar miao = 0;uchar cshi = 0;uchar cfen = 0;uchar cmiao = 0;void display(){ static unsigned char i = 0; SEGPORT = 0x0; seg_select = 1; seg_select = 0; SEGPORT = 0xff; bit_select = 1; bit_select = 0; SEGPORT = tempdata[i]; seg_select = 1; seg_select = 0; SEGPORT = bitdata[i]; bit_select = 1; bit_select = 0; i++; if(8 == i) { i = 0; } }void timer0_init(void){ EA = 1; TMOD |= 0x01; TH0 = (65536 - 20000) / 256; TL0 = (65536 - 20000) % 256; ET0 = 1; TR0 = 1;} void timer0_isr() interrupt 1{ static uchar i = 0; TH0 = (65536 - 20000) / 256; TL0= (65536 - 20000) % 256; i++; if(50 == i) { i = 0; miao++; if(60 == miao) { miao = 0; fen++; if(60 == fen) { fen = 0; shi++; if(24 == shi){ shi = 0; } } } } tempdata[0] = segdata[shi / 10]; tempdata[1] = segdata[shi % 10]; tempdata[2] = 0x40; tempdata[3] = segdata[fen / 10]; tempdata[4] = segdata[fen % 10]; tempdata[5] = 0x40; tempdata[6] = segdata[miao / 10]; tempdata[7] = segdata[miao % 10]; } void uart_init(void){ SCON = 0x50; TMOD |= 0x20; TH1 = 0xfd; TR1 = 1; EA = 1; ES = 1;}void uart_send_byte(unsigned char byte){ SBUF = byte; while(!TI); TI = 0;}void uart_send_str(unsigned char *s){ while(*s != '\0') { uart_send_byte(*s); s++; } }void uart_isr() interrupt 4{ unsigned char i = 0; unsigned char temp[6]; uart_send_str("Please input time :");for(i = 0; i < 6; i++){while(1){ if(RI) { temp[i] = SBUF; RI = 0;break;} }} uart_send_str("you input is :"); uart_send_str(temp); uart_send_str("\r\n"); shi = ((unsigned int)temp[0] - 48) * 10 + ((unsigned int)temp[1] - 48); fen = ((unsigned int)temp[2] - 48)* 10 + ((unsigned int)temp[3] - 48); miao = ((unsigned int)temp[4] - 48)* 10 + ((unsigned int)temp[5] - 48) ; }void main(){ timer0_init(); uart_init(); while(1){display();delay_us(200); }}
0 1
- 51单片机—串口时钟
- 51单片机—实时时钟
- 【单片机】51单片机时钟——利用中断
- 51单片机—定时器显示时钟
- 51单片机时钟程序
- 51单片机时钟输出
- 51单片机可调时钟
- 51单片机时钟
- 51单片机实现时钟
- 51单片机串口
- 51单片机的串口
- 51单片机串口通信
- 51单片机串口通讯
- 51单片机串口程序
- 51单片机串口通信
- 51 单片机串口实验
- 51单片机 串口通信
- 51单片机串口通信——串口设置
- 仿微信 个人头像修改 popPopupWindow实现Menus从底部弹出
- Qt 状态机框架学习
- ffmpeg命令行批量转换视频
- Java基础加强
- poi 3.11版本,最多65536条
- 51单片机—串口时钟
- Android插件化和热修复的区别和联系
- 在jsp中使用js获取session中的对象的例子。
- 青蛙王子
- Vue+webpack学习案例(一)-构建Vue项目
- Programming on Winodows with Python (I) -- Get/Set window property
- 微信 静默 授权登录 获取openid 实现方法
- Windows 下下载和安装Apache,APache的下载
- DbVisualizer解决中文乱码问题