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

📄 3310lcd.c

📁 超声波测距仪套件 电路图、GCC源代码资料
💻 C
字号:

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/pgmspace.h>
#include "MAIN.h"
#include "MISC.h"
#include "3310LCD.h"
#include "english_6x8_pixel.h"

/*-----------------------------------------------------------------------
LCD_init          : 3310LCD初始化
-----------------------------------------------------------------------*/
void LCD_init(void)
{
    PORTB &=~(1<<LCD_nRST);		// 产生一个让LCD复位的低电平脉冲
    _delay_loop_2(1000*FREQ/4);
    PORTB |= (1<<LCD_nRST);

    PORTB &=~(1<<LCD_nCE);			// 关闭LCD
    _delay_loop_2(10*FREQ/4);
    PORTB |= (1<<LCD_nCE);			// 使能LCD

    LCD_write_byte(0x21, 0);		// 使用扩展命令设置LCD模式
    LCD_write_byte(0x80+0x48, 0);	// 设置偏置电压
    LCD_write_byte(0x04+0x02, 0);	// 温度校正
    LCD_write_byte(0x10+0x03, 0);	// 1:48
    LCD_write_byte(0x20, 0);  		// 使用基本命令
    LCD_clear();		 			// 清屏
    LCD_write_byte(0x0c, 0);		// 设定显示模式,正常显示
    PORTB &= ~(1<<LCD_nCE);        // 关闭LCD
}

/*-----------------------------------------------------------------------
LCD_clear         : LCD清屏函数
 
编写日期          :2004-8-10 
最后修改日期      :2004-8-10 
-----------------------------------------------------------------------*/
void LCD_clear(void)
{
    unsigned int i;
    LCD_write_byte(0x0c, 0);
    LCD_write_byte(0x80, 0);
    for (i=0; i<504; i++)
        LCD_write_byte(0, 1);
}

/*-----------------------------------------------------------------------
LCD_set_XY        : 设置LCD坐标函数
 
输入参数:X       :0-83
          Y       :0-5
 
编写日期          :2004-8-10 
最后修改日期      :2004-8-10 
-----------------------------------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
    LCD_write_byte(0x40 | Y, 0);		// column
    LCD_write_byte(0x80 | X, 0);          	// row
}

/*-----------------------------------------------------------------------
LCD_write_char    : 显示英文字符
 
输入参数:c       :显示的字符;
 
编写日期          :2004-8-10 
最后修改日期      :2004-8-10 
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned char c)
{
    unsigned char line;
    const unsigned char *map= &font6x8[0][0];
    c -= 32;
    map+=c*6;
    line=6;
    while (line--)
        LCD_write_byte(pgm_read_byte(map++), 1);
}
/*-----------------------------------------------------------------------
LCD_write_english_String  : 英文字符串显示函数
 
输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置,x 0-83 ,y 0-5
 
编写日期          :2004-8-10 
最后修改日期      :2004-8-10 		
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,unsigned char *s)
{
    LCD_set_XY(X,Y);
    while (*s)
    {
        LCD_write_char(*s);
        s++;
    }
}

/*-----------------------------------------------------------------------
LCD_write_byte    : 使用SPI接口写数据到LCD
 
输入参数:data    :写入的数据;
          command :写数据/命令选择;
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char data, unsigned char command)
{
    PORTB&=~(1<<LCD_nCE) ;			// 使能LCD
    if (command==0)
        PORTB&=~(1<<LCD_DnC);	// 传送命令
    else
        PORTB|= (1<<LCD_DnC);	// 传送数据
    SPDR=data;			 		// 传送数据到SPI寄存器
    while ((SPSR & (1<<SPIF)) == 0)
        ;		// 等待数据传送完毕
    PORTB|= (1<<LCD_nCE) ;			// 关闭LCD
}

//写全屏
void LCD_draw_Screen(const unsigned char *map)
{
    unsigned int i;
    LCD_set_XY(0,0);
    for(i=0; i<504; i++)
    {
        LCD_write_byte(pgm_read_byte(map++), 1);
    }
}

⌨️ 快捷键说明

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