단편기==독립버튼+디지털관계수+중단법(9)
5002 단어 단편기 소프트웨어
#include
#include "delay.h"
sbit key1 = P3^2;
sbit seg_select = P1^0;
sbit bit_select = P1^1;
#define SEGPORT P0
unsigned char tempdata[2] = {0x3f,0x3f};
unsigned char segdata[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char bitdata[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void timer0_init(void)
{
EA = 1;
TMOD |= 0x01;
TH0 = (65536 - 10000) / 256;
TL0 = (65536 - 10000) % 256;
ET0 = 1;
TR0 = 1;
}
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(2 == i)
{
i = 0;
}
}
void timer0_isr(void) interrupt 1
{
TH0 = (65536 - 10000) / 256;
TL0 = (65536 - 10000) % 256;
display();
}
void int0_init()
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void int0_isr(void) interrupt 0
{
static unsigned char disdata = 0;
EX0 = 0;
delay_ms(10);
if(0 == key1)
{
while(!key1)
delay_ms(10);
while(!key1);
disdata++;
if(100 == disdata)
{
disdata = 0;
}
}
tempdata[0] = segdata[disdata / 10];
tempdata[1] = segdata[disdata % 10];
EX0 = 1;
}
void main()
{
timer0_init();
int0_init();
while(1);
}