📄 ledtest.c
字号:
/*********************cmdexplain***********************************
//cmd
- 0xF0 全屏清屏
- 0xF1 全屏闪烁1
- 0xF2 全屏闪烁2
- 0xF3 全屏闪烁3
- 0xF4 全屏关屏
- 0xF5 全屏关闭闪烁
//type+data
- 0x0f 正常显示X
- 0x0e 闪烁1显示X
- 0x0d 闪烁2显示X
- 0x0c 闪烁3显示X
*******************************************************************/
#include<reg52.h>
#include<absacc.h>
sfr AXUR = 0X8E;
#define U1 bit
#define U8 unsigned char
#define U16 unsigned int
#define U32 unsigned long
#ifndef BIT
#define BIT(x) (1 << (x))
#endif
sbit irqport = P3^2;
sbit busyport = P3^3;
sbit typeport = P3^5;
#define LEDCOMPORT P1
volatile U8 data addrbuf = 0;
volatile U8 data cmdbuf = 0;
U1 data FlashFlag_3 = 0;
U1 data FlashFlag_5 = 0;
U1 data FlashFlag_7 = 0;
U16 data TimeCount_3 = 0;
U16 data TimeCount_5 = 0;
U16 data TimeCount_7 = 0;
U8 pdata light_1 _at_ 120 ;
U8 pdata light_2 _at_ 121 ;
U8 pdata light_3 _at_ 122 ;
U8 data led_code[16] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,0x00,0x01,0x02,0x04,0x1e,0x40};//0,1,2,3,4,5,6,7,8,9,灭,A,b,C,d,-
U16 data row_code[7] = { 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000};
void test(void)
{
U8 i = 0;
for(i = 0; i<128;i++)
{
PBYTE[i] = 0x3f;
}
}
void scan_led(void)
{
U8 i, j;
U8 temp;
U8 temp1;
U8 temp2;
for(i = 0; i < 16; i++)
{
XBYTE[0X8000] = 0; XBYTE[0X9000] = 0;
for(j = 0; j < 7; j++)
{
temp2 = j*16 + i;
temp = PBYTE[temp2];
if (temp2 == 93) temp1 = temp;
else if (temp2 == 94) temp1 = temp;
else if (temp2 == 95) temp1 = temp;
else
{
switch(temp&0xf0)
{
case 0xf0:
temp &= 0x0f;
temp1 = led_code[temp];
break;
case 0xe0:
if(FlashFlag_3) temp = 0x0a;
else temp &= 0x0f;
temp1 = led_code[temp];
break;
case 0xd0:
if(FlashFlag_5) temp = 0x0a;
else temp &= 0x0f;
temp1 = led_code[temp];
break;
case 0xc0:
if(FlashFlag_7) temp = 0x0a;
else temp &= 0x0f;
temp1 = led_code[temp];
break;
}
}
XBYTE[row_code[j]] = temp1;
}
if (i < 8) XBYTE[0X8000] = BIT(i);
else XBYTE[0X9000] = BIT(i - 8);
XBYTE[0XA000] = light_1;
XBYTE[0XB000] = light_2;
XBYTE[0XC000] = light_3;
if(++TimeCount_3 >= 1000) {FlashFlag_3 = ~FlashFlag_3; TimeCount_3 = 0;}
if(++TimeCount_5 >= 2000) {FlashFlag_5 = ~FlashFlag_5; TimeCount_5 = 0;}
if(++TimeCount_7 >= 3000) {FlashFlag_7 = ~FlashFlag_7; TimeCount_7 = 0;}
}
}
void scan_cmd(void)
{
U8 i, temp;
if (cmdbuf)
{
switch(cmdbuf)
{
case 0xf0 : for(i = 0; i < 128; i++) PBYTE[i] = 0X0; break;
case 0xf1 : for(i = 0; i < 128; i++) {temp = PBYTE[i]; temp &= 0x0f; temp |= 0xe0; PBYTE[i] = temp;} break;
case 0xf2 : for(i = 0; i < 128; i++) {temp = PBYTE[i]; temp &= 0x0f; temp |= 0xd0; PBYTE[i] = temp;} break;
case 0xf3 : for(i = 0; i < 128; i++) {temp = PBYTE[i]; temp &= 0x0f; temp |= 0xc0; PBYTE[i] = temp;} break;
case 0xf4 : for(i = 0; i < 128; i++) PBYTE[i] = 0x0a; break;
case 0xf5 : for(i = 0; i < 128; i++) {temp = PBYTE[i]; temp &= 0x0f; PBYTE[i] = temp;} break;
case 0xe0 : light_1 = 0xff; light_2 = 0xff; light_3 = 0xff; break;
case 0xe1 : light_1 = 0x0; light_2 = 0x0; light_3 = 0x0; break;
}
cmdbuf = 0;
}
}
void InitSys(void)
{
U8 i;
AXUR = 0x01;
P1 = 0xff; P2 = 0xff; P3 = 0xff;
EX0 = 1; IT0 = 1;
busyport = 0;
for(i = 0; i < 128; i++) PBYTE[i] = 0xfa;
PBYTE[93] = 0x0; PBYTE[94] = 0x0; PBYTE[95] = 0x0;
light_1 = 0x0; light_2 = 0x0; light_3 = 0x0;
while(!irqport);
busyport = 1; IE0 = 0; EA = 1;
}
void main(void)
{
InitSys();
test();
while(1)
{
scan_led();
scan_cmd();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -