/*******main_func.c****/
#include "reg_define.h"
#include "system_init.h" /*通过system_init();调用*/
#include "IOport_init.h" /*包含后可直接使用所定义的IO端口*/
#include "Timer0_init.h" /*通过Timer0_init(unsigned int Tmer0_VAL);调用*/
#include "Timer1_init.h" /*通过Timer1_init(unsigned int Tmer0_VAL);调用*/
#include "Interrupt_server.h" /*包含后可直接到所对应的中断服务程序中编中断服务程序*/
#include "LED_display_6.h" /*通过LED_display_6(unsigned int 显示数据);调用*/
#include "LED_display_1.h"
#include "traffic.h"
#include <stdio.h>
int dx_red=30,nb_red=30;
unsigned int BJ_code[]={0x07,0x0b,0x0d,0x0e};
unsigned int bjcode,dj_code;
unsigned char STATE=1;
void delay(unsigned int d_t);
void Keyprocess(void);
void Bj_keyprocess(void);
void Dj_keyprocess(void);
void JT_keyprocess(void);
void TS_keyprocess(void);
void Set_time(void);
void JT_LED_display(void);
main()
{
system_init();
Timer0_init(0x6fff); /*Tmer0_VAL为TINT0的定时时间常数16.4ms*/
//Timer1_init(0x0ffff); /*Tmer0_VAL为TINT1的定时时间常数*/
while(1)
{
switch(STATE)
{
case 1:Bj_keyprocess();BJ_ADDR=BJ_code[bjcode];delay(100);break;/*不加会不转delay(100);*/
case 2:Dj_keyprocess();DJ_ADDR=dj_code;break;
case 3:JT_keyprocess();traffic();JT_LED_display();break;
case 4:TS_keyprocess();DJ_ADDR=dj_code;BJ_ADDR=BJ_code[bjcode];delay(100);traffic();break;
case 5:Set_time();LED_display_6(dx_red*100+nb_red);break;
default:break;
}
LED_display_1(STATE);
delay(10);
}
}
void Bj_keyprocess()
{
switch(key_code)
{
case 1:STATE=1;break;
case 2:STATE=2;break;
case 3:STATE=3;break;
case 4:STATE=4;break;
case 5:bj_derect=0;break; /*正转0*/
case 6:bj_derect=1;break; /*反转1*/
case 7:if(bj_speed>=3) bj_speed--;break; /*加速2*/
case 8:if(bj_speed<=50) bj_speed++;break; /*减速3*/
default : break;
}
}
void Dj_keyprocess()
{
switch(key_code)
{
case 1:STATE=1;break;
case 2:STATE=2;break;
case 3:STATE=3;break;
case 4:STATE=4;break;
case 5:dj_derect=0;break; /*正转0*/
case 6:dj_derect=1;break; /*反转1*/
case 7:if(dj_speed<dj_period) dj_speed++;break; /*加速2*/
case 8:if(dj_speed>=1) dj_speed--;break; /*减速3*/
default : break;
}
}
void JT_keyprocess()
{
switch(key_code)
{
case 1:STATE=1;break;
case 2:STATE=2;break;
case 3:STATE=3;break;
case 4:STATE=4;break;
case 9:STATE=5;break;
default : break;
}
}
void TS_keyprocess()
{
switch(key_code)
{
case 1:STATE=1;break;
case 2:STATE=2;break;
case 3:STATE=3;break;
case 4:STATE=4;break;
case 5:bj_derect=0;break;
case 6:bj_derect=1;break;
case 7:if(bj_speed>=3) bj_speed--;break;
case 8:if(bj_speed<=50) bj_speed++;break;
case 9:STATE=5;break;
case 11:dj_derect=0;break;
case 12:dj_derect=1;break;
case 13:if(dj_speed<dj_period) dj_speed++;break;
case 14:if(dj_speed>=1) dj_speed--;break;
default : break;
}
}
void Set_time(void)
{
switch(key_code)
{
case 5:dx_red+=1;break;
case 6:dx_red-=1;break;
case 7:nb_red+=1;break;
case 8:nb_red-=1;break;
case 10:STATE=4;break;
default : break;
}
if(dx_red>99)
dx_red=0;
if(dx_red<0)
dx_red=99;
if(nb_red>99)
nb_red=0;
if(nb_red<0)
nb_red=99;
}
void JT_LED_display()
{
if(t_traffic<dx_red)
LED_display_6((dx_red-t_traffic)*100);
if(t_traffic>=dx_red&&t_traffic<dx_red+10)
LED_display_6((dx_red+10-t_traffic)*100);
if(t_traffic>=dx_red+10&&t_traffic<dx_red+10+nb_red)
LED_display_6((dx_red+10+nb_red-t_traffic));
if(t_traffic>=dx_red+10+nb_red&&t_traffic<dx_red+10+nb_red+10)
LED_display_6((dx_red+10+nb_red+10-t_traffic));
}
void delay(unsigned int d_t)
{
int i,j;
for(i=0;i<d_t;i++)
{for(j=0;j<1;j++) {}}
}