?? 1602b_lcd._c
字號:
#include <iom16v.h>
#include <macros.h>
//#include "delay.c"
#define LCD_EN_PORT PORTC
#define LCD_RS_PORT PORTC
#define LCD_DATA_PORT PORTC
#define LCD_DATA_DDR DDRC
#define LCD_EN BIT(PC3) //portC5 out
#define LCD_RS BIT(PC2) //portC4 out
#define LCD_DATA 0xF0 //portC7/6/5/4 out
unsigned data_temp;
void delay_1ms(void)
{
uint i;
for (i=0;i<1140;i++);
}
void delay(uint n)
{
uint i=0;
for (i=0;i<n;i++)
delay_1ms();
}
/*-----------------------------------------------------------------------
LCD_write_char : 英文字符串顯示函數
輸入參數:*s :英文字符串指針;
X、Y : 顯示字符串的位置,X:0-15,Y:0-1
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第一行顯示寄存器地址:0XC0-0XCF
編寫日期 :2003-11-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
/*---------寫高4bit到LCD----*/
void LCD_Write_half_char(void)
{
LCD_DATA_PORT &= 0Xf0; //portc0~3=0
LCD_DATA_PORT |= data_temp&0x0f; //send LOW 4bit
LCD_EN_PORT |= LCD_EN; //EN端產生一個由低電平變高電平,寫LCD
delay_nms(1);
LCD_EN_PORT &= ~LCD_EN; //EN端產生一個由高電平變低電平,寫LCD
LCD_DATA_PORT &= 0Xf0;
delay_nms(1);
}
void LCD_write_char(unsigned command,unsigned data)
{
LCD_EN_PORT &= ~LCD_EN;
if (command == 0)
LCD_RS_PORT &= ~LCD_RS; //RS=0 發送命令
else
LCD_RS_PORT |= LCD_RS; //RS=1 發送數據
data_temp = data;
data_temp=data_temp >> 4;
LCD_Write_half_char();
data_temp = data;
LCD_Write_half_char();
delay_nms(1);
}
/*-----------------------------------------------------------------------
LCD_set_xy : 設置LCD顯示的起始位置
輸入參數:x、y : 顯示字符串的位置,X:0-15,Y:0-1
LCD第一行顯示寄存器地址:0X80-0X8F
LCD第一行顯示寄存器地址:0XC0-0XCF
編寫日期 :2004-8-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
void LCD_set_xy( unsigned char address )
{
LCD_write_char(0,address);
}
/*-----------------------------------------------------------------------
LCD_write_string : 英文字符串顯示函數
輸入參數:*s :英文字符串指針;
X、Y : 顯示字符串的位置
編寫日期 :2004-8-19
最后修改日期 :2004-8-19
-----------------------------------------------------------------------*/
/*void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_write_char(1,*s);
s ++;
}
}*/
void LCD_write_string(unsigned char address,unsigned char *s)
{
LCD_set_xy(address);
while (*s)
{
LCD_write_char(1,*s);
s ++;
}
}
/*---------------------------------------------------------
顯示單個字符函數
輸入參數:data :'w'或字符型數據0x37(數字7的ascii碼)
X、Y : 顯示字符串的位置
---------------------------------------------------------*/
/*void LCD_write_onechar(unsigned char X,unsigned char Y,unsigned char data)
{
LCD_set_xy( X, Y );
LCD_write_char( 1, data );
} */
void LCD_write_onechar(unsigned char address,unsigned char data)
{
LCD_set_xy( address );
LCD_write_char( 1, data );
}
void LCD_init(void)
{
LCD_write_char(0,0x38);
delay(1);
LCD_write_char(0,0x02);
delay(1);
LCD_write_char(0,0x28); // 顯示模式設置(不檢測忙信號)
delay(1);
LCD_write_char(0,0x08); // 顯示關閉
delay(1);
LCD_write_char(0,0x01); // 顯示清屏
delay(1);
LCD_write_char(0,0x06); // 顯示光標移動設置
delay(1);
LCD_write_char(0,0x0c); // 顯示開及光標設置
delay(5);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -