add segment display
This commit is contained in:
193
Interrupt_1.c
193
Interrupt_1.c
@ -7,20 +7,66 @@
|
||||
void delay_1500ms(void);
|
||||
|
||||
unsigned int timer0_counter = 150;
|
||||
int seg_pos = 0, seg_num = 0;
|
||||
|
||||
//LED
|
||||
bit lightoff = 1;
|
||||
bit lighton = 0;
|
||||
sbit P1_0 = P1^0;
|
||||
sbit P1_1 = P1^1;
|
||||
sbit P1_2 = P1^2;
|
||||
sbit P1_3 = P1^3;
|
||||
sbit P1_4 = P1^4;
|
||||
sbit P1_5 = P1^5;
|
||||
sbit P1_6 = P1^6;
|
||||
sbit P1_7 = P1^7;
|
||||
|
||||
void main(void){
|
||||
|
||||
char code LED_light[17] = {
|
||||
~0x00,
|
||||
~0x01,
|
||||
~0x03,
|
||||
~0x07,
|
||||
~0x0F,
|
||||
~0x1F,
|
||||
~0x3F,
|
||||
~0x7F,
|
||||
~0xFF,
|
||||
~0x7F,
|
||||
~0x3F,
|
||||
~0x1F,
|
||||
~0x0F,
|
||||
~0x07,
|
||||
~0x03,
|
||||
~0x01
|
||||
};
|
||||
|
||||
//Segment
|
||||
// <20>ŧi D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD><CFBE>}
|
||||
sbit P2_6 = P2^6;
|
||||
sbit P2_7 = P2^7;
|
||||
|
||||
// <20>ŧi<C5A7>C<EFBFBD>q<EFBFBD><71><EFBFBD>ܾ<EFBFBD><DCBE>禡
|
||||
void Slect_Seg(unsigned char number);
|
||||
void Display_Seg(unsigned char display);
|
||||
|
||||
//<2F>ŧi<C5A7>Ʀr<C6A6><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char code NUM[10] = {
|
||||
0x3F, // 0
|
||||
0x06, // 1
|
||||
0x5B, // 2
|
||||
0x4F, // 3
|
||||
0x66, // 4
|
||||
0x6D, // 5
|
||||
0x7D, // 6
|
||||
0x07, // 7
|
||||
0x7F, // 8
|
||||
0x6F // 9
|
||||
};
|
||||
|
||||
char code POS[6] = {
|
||||
~0x01, // 0xfe <20>N<EFBFBD>O 11111110
|
||||
~0x02, // 0000 0010
|
||||
~0x04, // 0000 0100
|
||||
~0x08, // 0000 1000
|
||||
~0x10, // 0001 0000
|
||||
~0x20 // 0010 0000
|
||||
};
|
||||
|
||||
|
||||
int main(void){
|
||||
int i = 0;
|
||||
//<2F>}<7D><> Timer0 <20>M Timer1
|
||||
TMOD = 0x11;
|
||||
|
||||
@ -32,93 +78,45 @@ void main(void){
|
||||
ET0 = 1; //<2F>}<7D><> TF0 <20><><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD>Ҳն}<7D><>
|
||||
EA = 1; //<2F>}<7D>Ҥ<EFBFBD><D2A4>_<EFBFBD>Ҳ<EFBFBD><D2B2>`<60>}<7D><>
|
||||
|
||||
|
||||
while(1){
|
||||
// do LED move up to down per 1.5 sec
|
||||
// using Timer 1 Mode 1 to generate 10ms delay
|
||||
P1 = 0xFF;
|
||||
while (1) {
|
||||
// ********* <20><><EFBFBD>@ LED *********
|
||||
for(i = 0; i < 16; i++) {
|
||||
P1 = LED_light[i];
|
||||
delay_1500ms();
|
||||
|
||||
P1_0 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_1 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_2 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_3 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_4 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_5 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_6 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_7 = lighton;
|
||||
delay_1500ms();
|
||||
|
||||
P1_7 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_6 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_5 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_4 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_3 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_2 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_1 = lightoff;
|
||||
delay_1500ms();
|
||||
|
||||
P1_0 = lightoff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void delay_1500ms(void){
|
||||
|
||||
int time = 0;
|
||||
while(time < 150) {
|
||||
int i;
|
||||
for (i = 0; i < 150; i++) {
|
||||
//<2F>]<5D>w<EFBFBD><77><EFBFBD>l<EFBFBD><6C>
|
||||
TF1 = 0;
|
||||
TR1 = 0;
|
||||
TL1 = (65536-9216) % 256;
|
||||
TH1 = (65536-9216) / 256;
|
||||
TF1 = 0;
|
||||
TL1 = (65536 - 9216) % 256;
|
||||
TH1 = (65536 - 9216) / 256;
|
||||
|
||||
//<2F>}<7D>ҭp<D2AD>ɾ<EFBFBD> timer1
|
||||
TR1 = 1;
|
||||
|
||||
//<2F><> TF1 <20>S<EFBFBD><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while(TF1 == 0);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>ɾ<EFBFBD>
|
||||
TR1 = 0;
|
||||
|
||||
//<2F>N TF1 <20>k<EFBFBD>s
|
||||
TF1 = 0;
|
||||
time++;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>p<EFBFBD>ɾ<EFBFBD>
|
||||
TR1 = 0;
|
||||
|
||||
//<2F>N TF1 <20>k<EFBFBD>s
|
||||
TF1 = 0;
|
||||
}
|
||||
|
||||
|
||||
// timer0 <20>b<EFBFBD>p<EFBFBD>ɨ쪺<C9A8>ɭ<EFBFBD>(TF0 = 1)<29>|<7C>I<EFBFBD>s<EFBFBD><73><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD>ƨ禡
|
||||
void my_timer0(void) interrupt 1 {
|
||||
|
||||
|
||||
//<2F>]<5D>w<EFBFBD><77><EFBFBD>l<EFBFBD><6C>
|
||||
TL0 = (65536 - 9216) % 256;
|
||||
TH0 = (65536 - 9216) / 256;
|
||||
@ -130,11 +128,52 @@ void my_timer0(void) interrupt 1 {
|
||||
|
||||
//<2F><> timer0_counter <20><> 0 <20>ɡA<C9A1><41><EFBFBD>@<40>C<EFBFBD>q<EFBFBD><71><EFBFBD>ܾ<EFBFBD>
|
||||
if (timer0_counter == 0){
|
||||
// <20><><EFBFBD>@<40>C<EFBFBD>q<EFBFBD><71><EFBFBD>ܾ<EFBFBD>
|
||||
|
||||
|
||||
// *********<2A><><EFBFBD>@<40>C<EFBFBD>q<EFBFBD><71><EFBFBD>ܾ<EFBFBD>*********
|
||||
Slect_Seg(POS[seg_pos]); // <20>]<5D>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>G
|
||||
Display_Seg(NUM[seg_num]); // <20><><EFBFBD>Ʀr
|
||||
seg_pos = (seg_pos + 1) % 6;
|
||||
seg_num = (seg_num + 1) % 10;
|
||||
|
||||
//<2F>N timer0_counter <20><><EFBFBD>ȳ]<5D>^ 150
|
||||
timer0_counter = 150;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Slect_Seg(unsigned char number) {
|
||||
int j = 0;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>(<28>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>I)
|
||||
P2_7 = 0;
|
||||
|
||||
// <20><><EFBFBD>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>G
|
||||
P0 = number;
|
||||
|
||||
// <20>}<7D>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>G<EFBFBD><47> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>
|
||||
P2_7 = 1;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>(<28>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD>G)
|
||||
for(j = 0; j < 120; j++);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>(<28><><EFBFBD>Y<EFBFBD>i<EFBFBD>h<EFBFBD><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>T<EFBFBD>w<EFBFBD>G)
|
||||
P2_7 = 0;
|
||||
}
|
||||
|
||||
void Display_Seg(unsigned char display) {
|
||||
int j = 0;
|
||||
// <20><><EFBFBD><EFBFBD> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>(<28>w<EFBFBD><77><EFBFBD><EFBFBD><EFBFBD>I)
|
||||
P2_6 = 0;
|
||||
|
||||
// <20><><EFBFBD>w<EFBFBD><77><EFBFBD>X
|
||||
P0 = display;
|
||||
|
||||
// <20>}<7D>ұ<EFBFBD><D2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>G<EFBFBD><47> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>
|
||||
P2_6 = 1;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>(<28>Y<EFBFBD><59><EFBFBD>X)
|
||||
for(j = 0; j < 120; j++);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> D <20><><EFBFBD><EFBFBD><EFBFBD>Ͼ<EFBFBD>(<28><><EFBFBD>Y<EFBFBD>i<EFBFBD>h<EFBFBD><68><EFBFBD><EFBFBD><EFBFBD>X<EFBFBD>T<EFBFBD>w<EFBFBD><77>)
|
||||
P2_6 = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user