#include "task.h"
#include <REGX52.H>
#include "lcd.h"
#include "system.h"
#include <stdio.h>
sbit key0=P3^2;
sbit key1=P3^3;
sbit ic_dex2=P2^5;
sbit ic_dex0=P2^7;
sbit ic_dex1=P2^6;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code table[]={"welcome.."};
uchar code table1[]={"WK--01"};
uchar code table2[]={"QQ 178898365 "};
uchar code state[]={"MY SERVO TEST .."};
uchar code prompt[]={"Angle"};
uchar disp_dat[3]={0};
void led_task(void)
{
unsigned char i;
for(i=0;i<8;i++)
{
P0=~(0X01<<i);
Delay_MS(500);
}
}
void Dis_ic(void)
{
ic_dex0=1;
ic_dex1=1;
ic_dex2=1;
P0=0XFF;
ic_dex0=0;
ic_dex1=0;
ic_dex2=0;
}
void Servo_task(void)
{
float angle=90;
Dis_ic();
LCD_Init(); //初始化
LCD_Write_String(0,0,state);
LCD_Write_String(0,1,prompt);
while(1)
{
Servo(angle);
sprintf(disp_dat,"%f",angle); //字符串格式化命令
LCD_Write_String(7,2,disp_dat);
if(key0==0)
{
Delay_MS(10);
if(key0==0)
{
angle+=10;
while(!key0);
}
}
if(key1==0)
{
Delay_MS(10);
if(key1==0)
{
angle-=10;
while(!key1);
}
}
}
}
void Welcome_task(void)
{
unsigned i;
Dis_ic();
LCD_Init();
for(i=16;i>3;i--)
{
LCD_Clear();
LCD_Write_String(i,0,table);
Delay_MS(500);
}
Delay_MS(1000);
LCD_Clear();
LCD_Write_String(5,0,table1);
LCD_Write_String(2,1,table2);
while(1)
{
LCD_Clear();
LCD_Write_String(5,0,table1);
LCD_Write_String(2,1,table2);
Delay_MS(500);
LCD_Clear();
LCD_Write_String(5,0,table1);
// LCD_Write_String(1,1,table2);
Delay_MS(500);
}
}
uchar keyscan(void) //键盘扫描
{
uchar temp,num;
P1=0xfe;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xeb:num=1;
break;
case 0xdb:num=2;
break;
case 0xbb:num=3;
break;
case 0x7b:num=4;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xe7:num=5;
break;
case 0xd7:num=6;
break;
case 0xb7:num=7;
break;
case 0x77:num=8;
break;
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
}
return num;
}
void Key_task(void)
{
uchar i;
while(1)
{
i=keyscan();
ic_dex1=1;
ic_dex0=0;
P0=0xff;
ic_dex0=1;
ic_dex1=0;
P0=tab[i];
}
}
|