//————————————————————————————
// Main.c
//————————————————————————————
// Copyright (C) 2013 Shenyang JYXD.
// WEN BO RUI
// Tool chain: KEIL Full c
//
//#pragma CD OE DB SB // Compilation directives
#include
#include
#define uchar unsigned char
#define uint unsigned int
uint Period; //Period刷新周期
uint PWM;
uint Pulse; //脉冲个数
uchar Speed; //速度变量
uchar count;
uint excount;
bit Gra; //突变/跳变总操控位
bit Gra7; //七彩渐亮渐灭操控位
bit Gra3; //红绿蓝渐亮渐灭操控位
bit BP; //亮到暗,暗到亮转换位
bit LEDdelay ; //LED守时到标志位
sbit key1 = P3^1; //把戏组合键1
sbit key2 = P3^0; //把戏组合键2
sbit key3 = P3^5; //速度组合键1
sbit key4 = P3^4; //速度组合键2
uchar led1[12]={0x10,0x030,0x20,0x60,0x40,0x50,0x70,0x50,0x40,0x60,0x20,0x30};//红、黄、绿、青、蓝、粉、白、粉、蓝、青、绿、黄
uchar led2[24]={0x10,0x00,0x30,0x00,0x20,0x00,0x60,0x00,0x40,0x00,0x50,0x00,
0x70,0x00,0x50,0x00,0x40,0x00,0x60,0x00,0x20,0x00,0x30,0x00};
uchar led3[3]={0x10,0x20,0x40}; //红、绿、蓝
uchar ledcount,ledcount1;
//***********************************************************
//以下界说函数
// 1毫秒延时函数delayms();把戏及速度扫描函数keyscan();
//***********************************************************
/*void delayms(unsigned int ms)
{
unsigned char i ;
while(ms–)
{
for(i = 0 ; i < 120 ; i++) ;
}
}*/
void Pattern1(); //把戏1函数———>跳变无灭灯进程
void Pattern2(); //把戏2函数———>跳变有灭灯进程
void Pattern34();
void keyscan()
{
if((key4==1)&&(key3==1)) {Speed = 20;Period = 25;} //预设4种速度200MS
if((key4==0)&&(key3==1)) {Speed = 50;Period = 50;} //500MS
if((key4==1)&&(key3==0)) {Speed = 100;Period = 100;} //1S
if((key4==0)&&(key3==0)) {Speed = 150;Period = 200;} //1.5S
if((key2==1)&&(key1==1)) {ledcount1 = 0;Pattern1();} //预设4种把戏
if((key2==0)&&(key1==1)) {ledcount1 = 0;Pattern2();}
if((key2==1)&&(key1==0)) {ledcount = 0;Gra3 = 1;Pattern34();}
if((key2==0)&&(key1==0)) {ledcount = 0;Gra7 = 1;Pattern34();}
}
void value()
{
if(Speed == 20) PWM = Pulse*8;
if(Speed == 50) PWM = Pulse*4; //脉冲个数
if(Speed == 100)PWM = Pulse*2;
if(Speed == 150)PWM = Pulse;
}
void Reset(void)
{
unsigned char code rst[ ]={0xe4,0xc0,0xe0,0xc0,0xe0,0x32};
(*((void (*)(void))(rst)))();
}
void main()
{
_nop_ ();
_nop_ ();
_nop_ ();
P1 = 0;
TMOD = 0x11; //11.0592M晶振的10ms守时初值(100分之一秒)
TH0 = 0x0db;
TL0 = 0x0ff;
TH1 = 0x0ff; //0.05ms(20000分之一秒)
TL1 = 0x0D1;
EA = 1; //敞开总中止答应
ET0 = 1; //答应T0守时器中止
ET1 = 1; //答应T1守时器中止
TR0 = 1; //敞开T0守时器
EX0=1; //开外部中止0
IT0=1; //下降沿触发
while(1)
{
keyscan();
}
}
//*************************************************************************
//Pattern1() 把戏函数1————-跳变无灭灯进程
//*************************************************************************
void Pattern1()
{
//keyscan();
Gra = 0; //跳变位=0
if(LEDdelay)
{
LEDdelay = 0;
P1 = led1[ledcount];
ledcount++;
if(ledcount>11)
{
ledcount = 0;
}
}
}
//***********************************************************************
//Pattern2() 把戏函数2————-跳变有灭灯进程
//***********************************************************************
void Pattern2()
{
//keyscan();
Gra = 0;
if(LEDdelay)
{
LEDdelay = 0;
P1 = led2[ledcount];
ledcount++;
if(ledcount>23)
{
ledcount = 0;
}
}
}
//***********************************************************************
//Pattern3() 把戏函数3————-3彩突变
//***********************************************************************
/*void Pattern3()
{
keyscan();
if(Speed == 20) Period = 25;
if(Speed == 50) Period = 50;
if(Speed == 100)Period = 100;
if(Speed == 150)Period = 200;
Gra = 1;
Gra3 = 1;
}*/