定时10分钟程序c语言,基于51的定时控程序(c语言).doc

基于51的定时控程序(c语言)

#include

#include

unsigned char data dis_digit;

unsigned char key_s, key_v,key_n,key_m,a,b,dhour,dmin;

unsigned char key_1,i,e,f, key_2,key_3,key_4,c,d,dhour1,dmin1;

/***************************1302:引角配置**********************/

sbit RST_1302=P2^6;

sbit IO_1302=P2^5;

sbit CLK_1302=P2^4;

sbit K1 = P1^0;

sbit K2 = P1^1;

sbit K3 = P1^2;

sbit K4 = P1^3;

sbit K5 = P1^4;

sbit K6 = P1^5;

sbit K7 = P1^6;

sbit K8 = P1^7;

sbit q=P2^0;

unsigned char clk_time[3]={0x10,0x21,0x18}; //秒,分,时寄存器初始值

unsigned char temp=0x80; // 地址80:秒写入寄存器

sbit ACC0=ACC^0;

sbit ACC7=ACC^7;

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;

bit scan_key();

void display();

void proc_key();

void delayms(unsigned char ms);

void write_1302(unsigned char addr,unsigned char dat);

unsigned char read_dat_1302(void);

void write_dat_1302(unsigned char dat);

unsigned char read_1302(unsigned char addr);

void main(void)

{

P0 = 0xff;

P3 = 0xff;

TMOD = 0x11; // 定时器0, 1工作模式1, 16位定时方式

TH1 = 0xdc;

TL1 = 0;

TH0 = 0xFC;

TL0 = 0x17;

write_1302(0x8e,0x00); //WP=0 写操作

for(i=0;i<3;i++)

{

write_1302(temp,clk_time[i]);

temp+=2;

}

write_1302(0x90,0xa5);

write_1302(0x8e,0x80); //WP=1 写保护

dis_digit = 0xfe;

dis_index = 0;

TCON = 0x01;

IE = 0x8a; // 使能timer0,1 中断

TR0 = 1;

TR1 = 1;

key_v=0x03;

key_m=0x03;

key_2=0x03;

key_4=0x03;

while(1)

{temp=0x81; // 地址81:秒写入寄存器

for(i=0;i<3;i++) //更新时间

{

display();

temp+=2;

}

P3 = 0xff; // 先关闭所有数码管

P0 = dis_buf[dis_index]; // 显示代码传送到P0口

P3 = dis_digit; //

dis_digit = _crol_(dis_digit,1); // 位选通值左移, 下次中断时选通下一位数码管

dis_index++; //

dis_index &= 0x07; // 8个数码管全部扫描完一遍之后,再回到第一个开始下一次扫描

if((clk_time[2]==dhour)&&(clk_time[1]==dmin))

q=0;

else if((clk_tim

你可能感兴趣的:(定时10分钟程序c语言)