急求单片机可调电子时钟的程序

来源:百度知道 编辑:UC知道 时间:2024/09/19 16:42:13
汇编和C都可以

P0为8位数据位
P2为8位数码管选择位,低电平选通
8位共阳极7段数码管
*******************************************************************************/

#include <reg52.h>
#include <intrins.h>

#define T2H_RELOAD 0xff //11.0592MHz 9600 baud rate at 12 clock
#define T2L_RELOAD 0xdc

unsigned char data dis_digit;
unsigned char code dis_code[11]={0xc0,0xf9,0xa4,0xb0, // 0, 1, 2, 3
0x99,0x92,0x82,0xf8,0x80,0x90, 0xff};// 4, 5, 6, 7, 8, 9, off
unsigned char data dis_buf[8];
unsigned char data dis_index;
unsigned char hour,min,sec;
unsigned char sec100;

void proc_key();
void inc_sec();
void inc_min();
void inc_hour();
void display();
void delayms(unsigned char ms);

void main(void)
{
P0 = 0xff;
P2 = 0xff;
TMOD = 0x11; // 定时器0, 1工作模式1, 16位定时方式
TH1 = 0xdc; //定时10ms
TL1 = 0;

TH0 = 0xFC; // 定时1ms
TL0 = 0x17;