/*******************************************************************
* 晶振:12MHZ
* 定时器0方式一,定时器周期0.5s
********************************************************************/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define TIMER_INIT 15536
/*char duan_en[10] = {0x3F, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};//共阴*/
char duan_en[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
}; //段选
sbit countdown_duan_en = P2^0;
sbit countdown_wei_en = P2^1;
sbit traffic_en = P2^2;
sbit b0 = P0^0;
sbit b1 = P0^1;
sbit b2 = P0^2;
sbit b3 = P0^3;
sbit sn_red_led = P0^1;
sbit sn_green_led = P0^2;
sbit sn_yellow_led = P1^0;
sbit sn_left_led = P0^0;
sbit sn_right_led = P0^3;
sbit ew_red_led = P0^6;
sbit ew_green_led = P0^5;
sbit ew_yellow_led = P1^1;
sbit ew_left_led = P0^4;
sbit ew_right_led = P0^7;
bit circle_flag = 1;
bit countdown_flag = 1;
uint circle_count = 0;
uchar circle_1_duration = 40;
uchar circle_1_left_duration = 10;
uchar circle_1_right_duration = 5;
uchar circle_1_transition_duration = 5;
uchar circle_1_flash_duration = 3;
uchar circle_1_flash_interval = 0.5;
uchar circle_1_yellow_duration = 2;
uchar circle_2_duration = 45;
uchar circle_2_left_duration = 10;
uchar circle_2_right_duration = 5;
uchar circle_2_transition_duration = 5;
uchar circle_2_flash_duration = 3;
uchar circle_2_flash_interval = 0.5;
uchar circle_2_yellow_duration = 2;
uchar circle_1_time[5];
uchar circle_2_time[5];
uchar timer_multiple = 2;
void traffic_led_on(bit _led);
void traffic_led_off(bit _led);
void traffic_led_flash(bit _led);
void countdown_led(uchar num, bit whichone);
void countdown_led_on();
void countdown_led_off();
void delay(int);
void xiaoying(void);
void readKey();
void initial(); //总初始化
void init_int(); //初始化中断
void init_timer(); //初始化定时器
void init_data(); //初始化数据
void reset_timer(); //定时器重置
void start_timer(); //开启定时器
void xiaoying()
{
delay(100);
P0=0x00;
}
void delay(int i)
{
int x,y;
for(x=i;x>0;x--)
{for(y=1;y<333;y++);}
}
void countdown_led(uchar num, bit whichone) //num的范围是0到99
{
if(whichone){
countdown_wei_en = 1;
b0 = 1;
b1 = 0;
b2 = 1;
b3 = 0;
countdown_wei_en = 0;
countdown_duan_en = 1;
P0 = duan_en[num / 10];
xiaoying();
countdown_duan_en = 0;
countdown_wei_en = 1;
b0 = 0;
b1 = 1;
b2 = 0;
b3 = 1;
countdown_wei_en = 0;
countdown_duan_en = 1;
P0 = duan_en[num % 10];
xiaoying();
countdown_duan_en = 0;
}
else{
countdown_wei_en = 1;
b0 = 1;
b1 = 0;
b2 = 1;
b3 = 0;
countdown_wei_en = 0;
countdown_duan_en = 1;
P0 = duan_en[num / 10];
xiaoying();
countdown_duan_en = 0;
countdown_wei_en = 1;
b0 = 0;
b1 = 1;
b2 = 0;
b3 = 1;
countdown_wei_en = 0;
countdown_duan_en = 1;
P0 = duan_en[num % 10];
xiaoying();
countdown_duan_en = 0;
}
}
void main()
{
uint m,i,j;
m=56;
for(i=m;i--;i>0)
{countdown_led(i, 1);
countdown_led(i, 0);}
}
评论0