硬件:ATMega16(8MRC)+HT1621+一體化紅外接收頭
思路:紅外解碼采用中斷捕捉方式(NEC編碼),顯示用液晶驅(qū)動HT1261
程序如下(WinAVR GCC環(huán)境編譯):
#include
#include
#include
#include
#include
#define HT1621_BIAS 0x29 // 設置LCD偏壓發(fā)生器為1/3偏壓,4個公共端
#define HT1621_RC256K 0x18 // 設置系統(tǒng)時鐘源為片內(nèi)RC(256KHz)振蕩器
#define HT1621_SYSTEN 0x01 // 打開系統(tǒng)時鐘振蕩器
#define HT1621_SYSDIS 0x00 // 停止系統(tǒng)時鐘振蕩器和LCD偏壓發(fā)生器
#define HT1621_LCDON 0x03 // 打開LCD偏壓振蕩器
#define HT1621_LCDOFF 0x02 // 關閉LCD偏壓發(fā)生器
#define HT1621_RAMSIZE0x10 // LCD顯示RAM大小16個字節(jié)
#define HT1621_TOPT0xE0
#defineHT1621_CS_SETPORTC|=(1< unsigned char lcd_dis_buf[16] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //************************************************************** //*****************************************************************
unsigned char capt_vect_cnt=0;
unsigned char ir_rx_data_flag=0;
unsigned char ir_rx_complete_flag=0;
unsigned char bitcnt=0;
unsigned int ir_plus[33];
unsigned int user_code=0;
unsigned int operate_code=0;
const unsigned char lcd7_code[] PROGMEM=
{
0xF5,// 0
0x05,// 1
0xB6,// 2
0x97,// 3
0x47,// 4
0xD3,// 5
0xF3,// 6
0x85,// 7
0xF7,// 8
0xD7,// 9
0xE7,// A
0x73,// B
0xF0,// C
0x37,// D
0xF2,// E
0xE2,// F
0x70,// L
0x67,// H
0xE0,// R
0x23// n
};
//**************************************************************
//*名稱:void ht1621_send_bit_h(unsigned char nbit,n) *
//*功能:向ht1621發(fā)送n位bit,先發(fā)送高位 *
//*參數(shù):nbit 送的bit位 len 發(fā)送bit的位數(shù) *
//*返回:無 *
//**************************************************************
void ht1621_send_bit_h(unsigned char nbit,unsigned char len)
{
unsigned char temp;
for(temp=0;temp
HT1621_WR_CLR;
if((nbit&0x80)==0x80)
{
HT1621_DATA_SET;
}
else
{
HT1621_DATA_CLR;
}
HT1621_WR_SET;
nbit<<=1;
}
}
//**************************************************************
//*名稱:void ht1621_send_bit_h(unsigned char nbit,n) *
//*功能:向ht1621發(fā)送n位bit,先發(fā)送低位 *
//*參數(shù):nbit 送的bit位 len 發(fā)送bit的位數(shù) *
//*返回:無 *
//**************************************************************
void ht1621_send_bit_l(unsigned char nbit,unsigned char len)
{
unsigned char temp;
for(temp=0;temp
HT1621_WR_CLR;
if((nbit&0x01)==0x01)
{
HT1621_DATA_SET;
}
else
{
HT1621_DATA_CLR;
}
HT1621_WR_SET;
nbit>>=1;
}
}
//**************************************************************
//*名稱:void ht1621_send_cmd(unsigned char cmd) *
//*功能:向ht1621發(fā)送命令 *
//*參數(shù):cmd 發(fā)送的命令 *
//*返回:無 *
//**************************************************************
void ht1621_send_cmd(unsigned char cmd)
{
HT1621_CS_CLR;
ht1621_send_bit_h(0x80,3); // 發(fā)送命令模式100
ht1621_send_bit_h(cmd,9); // 發(fā)送命令
HT1621_CS_SET;
}
//*名稱:void ht1621_write_byte(unsigned char byte,address) *
//*功能:向ht1621寫顯示數(shù)據(jù) *
//*參數(shù):byte 數(shù)據(jù)字節(jié) address 數(shù)據(jù)地址 *
//*返回:無 *
//**************************************************************
void ht1621_write_byte(unsigned char byte,unsigned char address)
{
address<<=2;
HT1621_CS_CLR;
HT1621_WR_CLR;
ht1621_send_bit_h(0xA0,3); // 發(fā)送寫數(shù)據(jù)模式101
ht1621_send_bit_h(address<<2,6); // 發(fā)送地址
ht1621_send_bit_l(byte,4); // 發(fā)送數(shù)據(jù)字節(jié)
HT1621_CS_SET;HT1621_WR_SET;
}
//*名稱:void ht1621_write_string(unsigned char *prt,address,len) *
//*功能:向ht1621寫入一組顯示數(shù)據(jù) *
//*參數(shù):prt 指向字節(jié)數(shù)組的指針 *
//* address 數(shù)據(jù)首地址 *
//* len 數(shù)組的長度 *
//*返回:無 *
//*****************************************************************
void ht1621_write_string(unsigned char *prt,unsigned char address,unsigned char len)
{
unsigned char temp;
HT1621_CS_CLR;
ht1621_send_bit_h(0xA0,3); //發(fā)送寫數(shù)據(jù)模式101
ht1621_send_bit_h(address<<2,6); //發(fā)送地址
if((len+address)>HT1621_RAMSIZE)
{
len=HT1621_RAMSIZE-address;
}
for(temp=0;temp
ht1621_send_bit_l(*prt++,8); //發(fā)送數(shù)據(jù)字節(jié)
}
HT1621_CS_SET;
}
//***********************************************************
//*名稱:void ht1621_int() *
//*功能:ht1621初始化 *
//*參數(shù):無 *
//*返回:無 *
//***********************************************************
void ht1621_int(void)
{
ht1621_send_cmd(HT1621_BIAS); // 設置LCD偏壓發(fā)生器為1/3偏壓,4個公共端
ht1621_send_cmd(HT1621_SYSTEN); // 打開系統(tǒng)時鐘振蕩器
ht1621_send_cmd(HT1621_LCDON); // 打開LCD偏壓振蕩器
ht1621_send_cmd(HT1621_RC256K); // 啟動內(nèi)部256KRC 振蕩器
}
//***********************************************************************************
//*名稱: delay_nus(unsigned int nms) *
//*功能: 延時nms *
//*參數(shù): 無 *
//*返回: 無 *
//***********************************************************************************
void delay_nus(unsigned int nms)
{
while(nms--)
{
_delay_loop_2(2);
}
}