add LED display
This commit is contained in:
105
Interrupt_1.c
Executable file → Normal file
105
Interrupt_1.c
Executable file → Normal file
@ -4,10 +4,21 @@
|
||||
#include <reg51.h>
|
||||
|
||||
// <20>ŧi<C5A7><69><EFBFBD>ɨ禡
|
||||
void delay10ms(void);
|
||||
void delay_1500ms(void);
|
||||
|
||||
unsigned int timer0_counter = 150;
|
||||
|
||||
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){
|
||||
|
||||
//<2F>}<7D><> Timer0 <20>M Timer1
|
||||
@ -21,33 +32,87 @@ 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><>
|
||||
|
||||
delay10ms();
|
||||
|
||||
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) {
|
||||
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 delay10ms(void){
|
||||
//<2F>]<5D>w<EFBFBD><77><EFBFBD>l<EFBFBD><6C>
|
||||
TF1 = 0;
|
||||
TR1 = 0;
|
||||
TL1 = (65536-9216) % 256;
|
||||
TH1 = (65536-9216) / 256;
|
||||
void delay_1500ms(void){
|
||||
|
||||
//<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;
|
||||
int time = 0;
|
||||
while(time < 150) {
|
||||
//<2F>]<5D>w<EFBFBD><77><EFBFBD>l<EFBFBD><6C>
|
||||
TF1 = 0;
|
||||
TR1 = 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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user