您当前的位置:五五电子网电子知识单片机-工控设备AVR单片机AVR ATMega16在段式液晶上显示红外码 正文
AVR ATMega16在段式液晶上显示红外码

AVR ATMega16在段式液晶上显示红外码

点击数:7877 次   录入时间:03-04 11:37:01   整理:http://www.55dianzi.com   AVR单片机

硬件:ATMega16(8MRC)+HT1621+一体化红外接收头

思路:红外解码采用中断捕捉方式(NEC编码),显示用液晶驱动HT1261

程序如下(WinAVR GCC环境编译):

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmsPACe.h>

#define     HT1621_BIAS         0x29       // 设置LCD偏压发生器为1/3偏压,4个公共端
#define     HT1621_RC256K       0x18         // 设置系统时钟源为片内RC(256KHz)振荡器
#define     HT1621_SYSTEN       0x01         // 打开系统时钟振荡器
#define     HT1621_SYSDIS       0x00         // 停止系统时钟振荡器和LCD偏压发生器
#define     HT1621_LCDON        0x03         // 打开LCD偏压振荡器
#define     HT1621_LCDOFF       0x02         // 关闭LCD偏压发生器
#define     HT1621_RAMSIZE 0x10         // LCD显示RAM大小16个字节
#define     HT1621_TOPT  0xE0           

#define  HT1621_CS_SET   PORTC|=(1<<PC4)
#define  HT1621_CS_CLR   PORTC&=~(1<<PC4)
#define  HT1621_WR_SET   PORTC|=(1<<PC3)
#define  HT1621_WR_CLR   PORTC&=~(1<<PC3)
#define  HT1621_DATA_SET   PORTC|=(1<<PC2)
#define  HT1621_DATA_CLR   PORTC&=~(1<<PC2)
#define      IR_RX    (PIND&(1<<PD2))

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发送n位bit,先发送高位                     *
//*参数: nbit 送的bit位   len 发送bit的位数                 *
//*返回: 无                                                 *
//**************************************************************
void ht1621_send_bit_h(unsigned char nbit,unsigned char len)
 {  
  unsigned char temp;
  for(temp=0;temp<len;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发送n位bit,先发送低位                     *
//*参数: nbit 送的bit位   len 发送bit的位数                 *
//*返回: 无                                                 *
//**************************************************************
void ht1621_send_bit_l(unsigned char nbit,unsigned char len)
 {  
  unsigned char temp;
  for(temp=0;temp<len;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发送命令                                   *
//*参数: cmd 发送的命令                                     *
//*返回: 无                                                 *
//**************************************************************
void ht1621_send_cmd(unsigned char cmd)
 {
  
  HT1621_CS_CLR;
  ht1621_send_bit_h(0x80,3);   // 发送命令模式100
  ht1621_send_bit_h(cmd,9);    // 发送命令
  HT1621_CS_SET;
 }

//**************************************************************

[1] [2] [3]  下一页


本文关键字:暂无联系方式AVR单片机单片机-工控设备 - AVR单片机