⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2402.c

📁 用AVR M8控制PT2134音频芯片的程序,显示是LCM2402,还带有有红外遥控功能.
💻 C
字号:

 
//--------------------------------------------------------------------------------
#include <avr/io.h> //MCU
#include <stdio.h> 
#include <util/delay.h> 
#include"2402.h"

//---------------------------延时------------------------------------------------
void Delay_10ms(uchar _time) 
{ 
    while( _time>0) 
    { 
        _delay_ms(7); 
        _time--; 
    } 
} 

  
//-------------------------设置所需函数 -----------------------------------------

//写数据线命令(四线模式数据要分两次写) 
void out_dataline(uchar line) 
{ 
        SETBIT(LCD_PORT,EN);   //EN=1 
        LCD_PORT&=0Xf0;               //清低四位端口 
        LCD_PORT|=line/16;           //写高四位数据 
        CLRBIT(LCD_PORT,EN);   //EN=0 

  
        SETBIT(LCD_PORT,EN);   //EN=1 
        LCD_PORT&=0Xf0;               //清低四位端口 
        LCD_PORT|=line&0x0f;           //写低四位数据 
        CLRBIT(LCD_PORT,EN);   //EN=0 
} 


//----------------------一、写指令函数 -------------------------------------------
void write_command(unsigned char com) 
{ 
        _delay_us(40);        //delay 
        CLRBIT(LCD_PORT,RS);  //RS=0 
        out_dataline(com); 
} 
  
//----------------------二、写数据函数(四线模式数据要分两次写) ------------------

void write_data(unsigned char data) 
{ 
        _delay_us(40);        //delay 
        SETBIT(LCD_PORT,RS);  //RS=1 
        out_dataline(data); 
} 


//-----------------------三、初始化LCD1602函数 ----------------------------------
void LCD_init(void) 
{ 
        LCD_DDR=0xff;         //设为输出 
      //  CLRBIT(LCD_PORT,RW);  //设为永远W状态 
         
        _delay_ms(100); 
        write_command(0x33); 
        Delay_10ms(2);  
        write_command(0x32); 
        Delay_10ms(2); 
  
        write_command(0x28); 
        write_command(0x0c);  //显示开--对应开关显示控制指令 
        write_command(0x01);  //清屏--对应清屏指令 
        Delay_10ms(2);         //delay 
} 


//------------------------四、写地址函数 -----------------------------------------

void LCD_set_addr(unsigned char x,unsigned char y)//x:0~15,y:0~1 
{ 
        if(y)  
                write_command(0xc0+x);//第二行显示 
        else   
                write_command(0x80+x);//第一行显示 
} 
  


//--------------------------五、写字符函数 --------------------------------------
void LCD_write_char(unsigned char X,unsigned char Y, 
                    unsigned char data) //列x=0~15,行y=0,1 
{ 
        LCD_set_addr( X, Y ); //写地址 
        write_data(data); 
} 


//--------------------------六、写字符串函数------------------------------------- 

void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s) //列x=0~15,行y=0,1 
{ 
    LCD_set_addr( X, Y ); //写地址     
    while (*s)  // 写显示字符 
    { 
                write_data( *s ); 
                s ++; 
    } 
       
} 
  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -