📄 platup070710.c
字号:
//plat2up.c(电子看板)// close 0 dig
//*****************************************************************************************//
//显示面板: * 今日计划 8 8 8 8 * // //
// * 现在计划 8 8 8 8 * // //
// * 现在实绩 8 8 8 8 * // //
// * 现在时间 8888年88月88日88:88 * // //
//=========================================================================================//
//操作说明: //
// 按计数键:进行计数及显示close 0 disp //
// 按清 0键:进行现在实绩清0和现在计划清0,同时显示 //
// 按设定键:第1次进行今日计划设定及显示; //
// 第2次进行今日工时设定及显示; //
// 第3次进行现在时间设定及显示; //
// 第4次进行设定确认并退出。 //
// 0~9数字键:进行数据设定,按1下后自动到下一位设定,并在设定位进行循环移位 //
// 暂停计数键:ON时计数键无效且现在计划暂停计数,现在时间断续。 //
//*****************************************************************************************//
#include <regx51.h>
#define uchar unsigned char
#define uint unsigned int
#define TTH0 (65536-1000)/256 //1ms 初始化中断扫描
#define TTL0 (65536-1000)%256
uchar buffer[24]; //显示代码缓存
uchar code table[]= {0x3f,0x06,0x5b,0x4f, // 共阴 用74ls07驱动
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
/*{ 0xC0,0xF9,0xA4,0xB0, //共阳用74ls04驱动
0x99,0x92,0x82,0xF8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e },*/
uchar MRD; //键号存储
uchar cnt_set; //设定计数器
bdata uchar flag=0; //标示位
sbit flagminute=flag^0; //分标示
sbit flag_set=flag^1; //设定标示
sbit flag_second=flag^2; //秒标示
sbit ir_enable=flag^3; //红外接收成功标示
sbit ir_reject=flag^4; //红外不接收标示
sbit flag_day=flag^5; //天标示
uchar hour; //计时小时暂存器
uchar minute; //计时分钟暂存器
uchar second; //计时秒暂存器
uint cnt01ms; //0.1ms计数器
uchar cnt_flash; //闪烁计数器
uchar cnt; //显示中断用
uchar line; //闪烁位置
uint counter; //实绩计数器
uint minutecounter; //分钟计数器
uint worktime; //设定工作时间
uint plancount; //设定计划生产数量暂存器
uchar connt; //红外中断接收状态码暂存器
uint tmp0; //红外中断前1时间暂存器
uint tmp1; //红外中断现在时间暂存器
uchar ir_data; //红外接收码暂存器
uchar ir_data1; //红外接收1码暂存器
uchar ir_data2; //红外接收2码暂存器
uchar year,mouth,day,day0; //年月日标示
void delay(unsigned int i){ //延时10US程式
while(i>0)i--;
}
void timerint0 () interrupt 1 { //单个7SEG1ms扫描;共16个7SEG需16ms扫描完成一个循环
TL0 = TTL0; //1ms定时
TH0= TTH0;
if((flag_set==1)&&(cnt==line)){ //有设定值则该位闪烁
P0=0x00; //关显示码
cnt_flash++;
if(cnt_flash==30){ //过30MS
cnt_flash=0;
P0=table[buffer[cnt]]; //显示显示码
}
}
else if((flag_second==1)&&(cnt==21)){flag_second=0;P0=table[buffer[cnt]]|0x80;}
else { P0=table[buffer[cnt]];}
if(cnt<16){ //片选74HC154
WR=0;
P1=cnt;
}
else if(cnt==16){ //片选74HC138
WR=1;
P1=0;
}
else {
WR=1;
P1=cnt;
}
if(cnt++==24) cnt=0;
}
void timer1() interrupt 3
{
tmp1++;
cnt01ms++;
if(cnt01ms==10000){
cnt01ms=0;second++;flag_second=1;
if(second==60){
second=0;minute++;flagminute=1;
if(minute==60){
minute=0;hour++;
if(hour==24){
flag_day=1;hour=0;
}
}
}
}
}
void ir_succeed() { //接收成功进行效对程式
if(ir_data1==0x67){
ir_data = ir_data2;
ir_enable=1;
ir_reject=1;
TH1=0;
TL1=0;
connt=0;
}
}
void JISH_INT0()interrupt 2 { //红外接收程序
uint tmp; //红外中断时段暂存器
if(ir_reject)return; //有红外拒收旗标,拒绝接收其它码
tmp=tmp1-tmp0; //现在的时间中断值-前一中断值=时段
tmp0=tmp1; //把现在的时间中断值=前一中断值
if(connt == 0) //接收第0码(头码)
{
if((tmp >98) && (tmp <146 )) //12160 //是第头码
{
connt++;
return;
} else{ //不是第0码则返回接收状态0码
connt = 0;
return;
}
}
/////////////////////////////////////////////////////
if(connt !=0)
{
if(connt <= 8) //是第1~8状态码
{
if((tmp >9) && (tmp <13 )) //1120 //是0码
{
ir_data1 <<= 1;
connt++;
return;
}
else if((tmp >18) && (tmp <26) ) //2240//是1码
{
ir_data1 <<= 1;
ir_data1 |= 0x01;
connt++;
return;
}
else{ //不是0和1 码则返回状态0码
connt = 0;
return;
}
}
//////////////////////////////////////////////////////
if(connt == 9)
{
if((tmp >40) && (tmp <60 )) //5040 //是过渡码
{
connt++;
return;
}
else { //否则返回状态0码
connt=0;
return;
}
}
//////////////////////////////////////////////////////
if(connt > 9 && connt <= 17) //是第10~17状态码
{
if((tmp >9) && (tmp <13 )) //1120//是0码
{
ir_data2 <<= 1;
connt++;
if(connt == 18)ir_succeed();
return;
}
else if((tmp >18) && (tmp <26) ) //2240//是1码
{
ir_data2 <<= 1;
ir_data2 |= 0x01;
connt++;
if(connt == 18)ir_succeed();
return;
}
else{ //否则返回状态0码
connt = 0;
return;
}
}
}
}
uchar key(){ //红外接收码转换为键值码
uchar i,LREC,ir_tmp;
uchar lrec[] ={0x98,0x08,0x88,0x48,0xc8,0x28,0xa8,0x68,0xe8,0x18,0x50,0xa0};
LREC=0;
for (i=0;i<12;i++){
if(lrec[i]==ir_data){
ir_tmp=i;
LREC=1;
}
}
if(LREC)return ir_tmp;else return 0XFF; // 是接收码返回 ir_tmp;否则返回0XFF
}
void KEYHANDLE(){
switch(MRD){
//设定键1-今日计划;2-工作时间;3-现在时间;4-确认 c
case 10:MRD=0XFF;flag_set=1;cnt_set++;
if(cnt_set==1){line=0; }
else if(cnt_set==2){line=4; }
else if(cnt_set==3){line=14;}
else if(cnt_set==4){line=20;}
else if(cnt_set==5){flag_set=0;cnt_set=0;second=0;}
break;
case 11:MRD=0XFF;counter=0;minutecounter=0;break; //实绩计数器&分钟计数器清0
default: if((MRD<=9)&&(flag_set==1)){ //输入设定值
buffer[line]=MRD;
if(cnt_set==1){ //设定今日计划数量
line++;
if(line>3)line=0;
plancount=buffer[0]*1000+buffer[1]*100+buffer[2]*10+buffer[3];
}
else if(cnt_set==2){ //设定今日生产时间
line++;
if(line>7)line=4;
worktime=buffer[4]*1000+buffer[5]*100+buffer[6]*10+buffer[7];
}
else if(cnt_set==3){ //设日期
line++;
if(line>19)line=14;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -