|
初次接觸1T的stc15W408as單片機(jī),不清楚哪些程序要改動(dòng)?
請(qǐng)教如何把89c52單片機(jī)紅外解碼程序移植到15W408中運(yùn)行?
#include <REGX52.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0X88,0X83,0XC6,0XA1,0X86,0X8E,0xFF};
sbit IR = P3^2; //紅外接收端
uchar N[4]; //識(shí)別碼,操作碼存放
uchar sj=0;
void XSQ(void);
void YS(uchar time);
/****************** 主函數(shù) *******************/
void main(void)
{
IT0 = 1;
EX0 = 1;
EA = 1;
while(1)
{
XSQ();
}
}
/**********************數(shù)碼管顯示函數(shù)************************/
void XSQ(void)
{
P0=tab[X3];
P2_6=0;
YS(1); //操作碼
P2_6=1;
P0=tab[X4];
P2_7=0;
YS(1);
P2_7=1;
}
/********************** 外部中斷函數(shù)************************/
void exint0() interrupt 0
{
uint cnt;
uchar i;
EX0 = 0;
cnt = 0;
while(!IR) cnt++; //記錄引導(dǎo)碼時(shí)間
if(cnt < 1000){EX0=1;return;} //9ms的計(jì)數(shù)值(12MHz:1000< cnt <1500)
cnt = 0;
while(IR) if(cnt++ > 400){EX0=1;return;} //防卡死,超時(shí)保護(hù)(12MHz: > 300)
if(cnt < 200){EX0=1;return;} //(12MHz不分頻: <260)
for(i=0; i<32; i++) //讀取32位位碼
{
cnt = 0;
while(!IR);
while(IR) if(cnt++ > 200){EX0=1;return;} //超時(shí)保護(hù)(12MHz:>=200)
N[i/8] >>= 1;
if(cnt>60) N[i/8] |= 0x80; //0和1的計(jì)數(shù)界線(12MHz:< 109)
}
if(N[0] == ~N[1] && N[2] == ~N[3]) //校驗(yàn)識(shí)別碼,操作碼
{
X1 = N[0]/16;
X2 = N[0]%16;
X3 = N[2]/16;
X4 = N[2]%16;
}
EX0 = 1;
}
/***************************************************************
函數(shù)功能:按鍵消抖 延時(shí)程序
入口參數(shù):1ms×time (晶振=12MHz)
***************************************************************/
void YS(uchar time)
{
uchar i,j;
for(i=0; i<time; i++)
for(j=0; j<247; j++)
_nop_();
}
|
|