📄 user.c
字号:
#include<spce061a_chf.h>
#include"host.h"
#include"bit.h"
extern t_counter;
extern r_timer[18];
extern kk;
unsigned char number[3]={0};
unsigned int a_length=0;
unsigned int b_length=0;//开始时候,吊绳的长度
unsigned int *data_addr=0xf100;
unsigned int data_key=0;
///////////////////////////////////////////
//函数:void system_init(void)
//描述:系统初始化函数
//参数:无
//返回:无
/////////////////////////////////////////////
void system_init(void)
{
*P_IOA_Dir=0x0fff;
*P_IOA_Attrib=0x0fff;
*P_IOA_Data=0x0000;
*P_IOB_Dir=0xfff4;
*P_IOB_Attrib=0xfff4;
*P_IOB_Data=0x0000;
}
///////////////////////////////////////////
//函数:void Tx_hanshu(unsigned int temp_data);
//描述:发送函数
//参数:要发送的数据
//返回:无
/////////////////////////////////////////////
void Tx_hanshu(unsigned int Tx_temp_data)
{
unsigned int i=0;
*P_TimerA_Data = 0xff61;
*P_TimerA_Ctrl = 0x0036;//开始先关闭;设置TimerA,使IOB8输出38KHz的PWM波形,供红外发射调制作
*P_INT_Ctrl=0x0010;
asm("irq on");
while(t_counter<=16)
{
*P_TimerA_Ctrl = 0x03f0;
}
*P_TimerA_Ctrl = 0x0036;
t_counter=0;
while(t_counter<=3)
{
*P_TimerA_Ctrl = 0x0036;
}
for(i=0;i<16;i++)
{
if(Tx_temp_data&0x8000)
{
t_counter=0;
while(t_counter<3)
{
*P_TimerA_Ctrl = 0x03f0;
}
t_counter=0;
while(t_counter<1)
{
*P_TimerA_Ctrl = 0x0036;
}
}
else
{
t_counter=0;
while(t_counter<1)
{
*P_TimerA_Ctrl = 0x03f0;
}
t_counter=0;
while(t_counter<1)
{
*P_TimerA_Ctrl=0x0036;
}
}
Tx_temp_data<<=1;//左移一位
}
}
///////////////////////////////////////////
//函数:unsigned int Rx_hanshu(void)
//描述:接收函数
//参数:无
//返回:接收到的数据
/////////////////////////////////////////////
unsigned int Rx_hanshu(void)
{
unsigned int j=0;
unsigned int Rx_temp_data=0;
*P_SystemClock=clock_A;//24.576--24.576/8
Set_TimerA_Data(start_dataA);//定时器A从0开始计数
Set_TimerA_Ctrl(stopA);//开始先不计数
*P_INT_Ctrl=0x0200;//开IRQ3_EXIT2中断
asm("irq on");
while(kk<18)
{
*P_Watchdog_Clear=0x01;
} //等待译码结束
asm("nop");
kk=0;
if((r_timer[1]<2000)&(r_timer[1]>1400))//说明译码结束
{
for(j=2;j<18;j++)
{
if(r_timer[j]>250)//说明数据位开始
{
//*Rx_temp_data<<=1;
//*Rx_temp_data=Rx_temp_data|1;
r_timer[j]=1;
}
if((r_timer[j]<250)&(r_timer[j]>80))
{
//Rx_temp_data<<=1;
//Rx_temp_data=Rx_temp_data|0;
r_timer[j]=0;
}
/*if(j<17)
{
Rx_temp_data<<=1;
}
else
{
Rx_temp_data+=0;
}*/
Rx_temp_data<<=1;
Rx_temp_data=Rx_temp_data|r_timer[j];
}
*P_Watchdog_Clear=0x01;
return (Rx_temp_data);
}
return (0xf001);
}
///////////////////////////////////////////
//函数:void init_keyIO(void)
//描述:键盘IO口初始化函数
//参数:无
//返回:无
/////////////////////////////////////////////
void init_keyIO(void)
{
PA_Dir->byte.byteh=0x0f;
PA_Attrib->byte.byteh=0x0f;
PA->byte.byteh=0x00;
}
///////////////////////////////////////////
//函数:unsigned int get_keyvalue(void)
//描述:键盘取值函数
//参数:无
//返回:返回相应的键值
/////////////////////////////////////////////
unsigned int get_keyvalue(void)
{
unsigned int keyhang[4]={0x0e,0x0d,0x0b,0x07};//行扫描码
unsigned int keyi=0;
for(keyi=0;keyi<4;keyi++)
{
PA->byte.byteh=keyhang[keyi];
if(P0_12==0)
{
while(P0_12==0)
{
*P_Watchdog_Clear=0x01;
}
return(keyi*4);
}
else if(P0_13==0)
{
while(P0_13==0)
{
*P_Watchdog_Clear=0x01;
}
return(keyi*4+1);
}
else if(P0_14==0)
{
while(P0_14==0)
{
*P_Watchdog_Clear=0x01;
}
return(keyi*4+2);
}
else if(P0_15==0)
{
while(P0_15==0)
{
*P_Watchdog_Clear=0x01;
}
return(keyi*4+3);
}
}
return 16;
}
///////////////////////////////////////////
//函数:unsigned int key_scan_delay(void)
//描述:加按键消抖的键盘扫描函数
//参数:无
//返回:有按键按下就返回1,否则返回0
/////////////////////////////////////////////
unsigned int key_scan_delay(void)
{
if(key_scan())
{
delay();//延时5ms
if(key_scan())
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
///////////////////////////////////////////
//函数:unsigned int key_scan(void)
//描述:键盘扫描函数
//参数:无
//返回:有按键按下就返回1,否则返回0
/////////////////////////////////////////////
unsigned int key_scan(void)
{
init_keyIO();
if(PA->byte.byteh==0xf0)
{
return 0;
}
else
{
return 1;
}
}
///////////////////////////////////////////
//函数:void delay(void)
//描述:键盘延时函数
//参数:无
//返回:无
/////////////////////////////////////////////
void delay(void)
{
unsigned int timei=5000;
while(timei--)
{
asm("nop");
*P_Watchdog_Clear=0x01;
}
}
///////////////////////////////////////////
//函数:void delay1(void)
//描述:键盘延时函数
//参数:无
//返回:无
/////////////////////////////////////////////
void delay1(void)
{
unsigned int timei=0xdfff;
while(timei--)
{
asm("nop");
*P_Watchdog_Clear=0x01;
}
}
///////////////////////////////////////////
//函数:void input_hanshu(void)
//描述:输入楼层号,输入格式:3-1
//参数:无
//返回:无
/////////////////////////////////////////////
void input_hanshu(void)
{
unsigned int count_i=0;
unsigned int key_temp1=0;
unsigned int key_f1=0;
SetPaintMode(0,0xffff);
FontSet(0,0);
FontSet(1,0xffff);
PutChar(50,1,':');
while(count_i<3)
{
while((key_f1==0)|(key_temp1==16))
{
key_f1=key_scan_delay();
while(key_f1==0)
{
key_f1=key_scan_delay();
*P_Watchdog_Clear=0x01;
}
key_temp1=get_keyvalue();
if(key_temp1>10)
{
key_temp1=16;
}
}
key_f1=0;
number[count_i]=key_temp1+48;
if(count_i==1)
{
number[count_i]='-';
PutChar(count_i*5+2,20,number[count_i]);
}
PutChar(count_i*5,20,number[count_i]);
//PutChar(count_i*5+2,20,number[count_i]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -