?? main.c
字號:
#include <io.h>
//#include <MACROS.h>
#include "Define.h"
#include "5110.h"
/******************************************************************************/
void Delay_us(unsigned int time)
{
while(time--);
}
void Delay_ms(unsigned int time)
{
while(time--)
{
Delay_us(1000);
}
}
void main(void)
{
LCD_init();//初始化液晶
LCD_clear();
SETBIT(DDRC,BACKLED_EN); //配置背光控制端口
CLEARBIT(PORTC,BACKLED_EN); //使能背光
while(1)
{
LCD_clear();
LCD_write_english_string(0,0,"---ADEmbed----");
LCD_write_english_string(0,5,"www.");
LCD_write_english_string(21,5,"adembed.");
LCD_write_english_string(66,5,"com");
LCD_write_chinese_string(0,3,12,7,0,0);
Delay_ms(5000);
LCD_clear();
LCD_draw_bmp_pixel(0,0,AVR_bmp,48,24);
Delay_ms(2000);
}
}
/********************************************************************************************************************/
void LCD_init(void)
{
//先設置為輸出
SETBIT(LCD_DIR,SCLK);
SETBIT(LCD_DIR,SDIN);
SETBIT(LCD_DIR,LCD_DC);
SETBIT(LCD_DIR,LCD_CE);
//SETBIT(LCD_DIR,LCD_RST);
// 產生一個讓LCD復位的低電平脈沖
//CLEARBIT(LCD_PORT,LCD_RST);//LCD_RST = 0;
//delay_1us();
//SETBIT(LCD_PORT,LCD_RST);//LCD_RST = 1;
// 關閉LCD
CLEARBIT(LCD_PORT,LCD_CE);//LCD_CE = 0;
delay_1us();
// 使能LCD
SETBIT(LCD_PORT,LCD_CE);//LCD_CE = 1;
delay_1us();
LCD_write_byte(0x21, 0); // 使用擴展命令設置LCD模式
LCD_write_byte(0xc8, 0); // 設置偏置電壓
LCD_write_byte(0x06, 0); // 溫度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 設定顯示模式,正常顯示
// 關閉LCD
CLEARBIT(LCD_PORT,LCD_CE);//LCD_CE = 0;
}
/********************************************************************************************************************/
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);
}
}
/********************************************************************************************************************/
void delay_1us(void) //1us延時函數
{
unsigned int i;
for(i=0;i<12000;i++);
}
/********************************************************************************************************************/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
/********************************************************************************************************************/
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
{
LCD_write_byte(font6x8[c][line], 1);
}
}
/********************************************************************************************************************/
/*-----------------------------------------------------------------------
LCD_write_english_String : 英文字符串顯示函數
輸入參數:*s :英文字符串指針;
X、Y : 顯示字符串的位置,x 0-83 ,y 0-5
-----------------------------------------------------------------------*/
void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
{
LCD_set_XY(X,Y);
while (*s)
{
LCD_write_char(*s);
s++;
}
}
/********************************************************************************************************************/
/*-----------------------------------------------------------------------
LCD_write_chinese_string: 在LCD上顯示漢字
輸入參數:X、Y :顯示漢字的起始X、Y坐標;
ch_with :漢字點陣的寬度
num :顯示漢字的個數;
line :漢字點陣數組中的起始行數
row :漢字顯示的行間距
-----------------------------------------------------------------------*/
void LCD_write_chinese_string(unsigned char X, unsigned char Y,unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row)
{
unsigned char i,n;
LCD_set_XY(X,Y); //設置初始位置
for (i=0;i<num;)
{
for (n=0; n<ch_with*2; n++) //寫一個漢字
{
if (n==ch_with) //寫漢字的下半部分
{
if (i==0) LCD_set_XY(X,Y+1);
else
{
LCD_set_XY((X+(ch_with+row)*i),Y+1);
}
}
LCD_write_byte(HZK[line+i][n],1);
}
i++;
LCD_set_XY((X+(ch_with+row)*i),Y);
}
}
/********************************************************************************************************************/
/*-----------------------------------------------------------------------
LCD_draw_map : 位圖繪制函數
輸入參數:X、Y :位圖繪制的起始X、Y坐標;
*map :位圖點陣數據;
Pix_x :位圖像素(長)
Pix_y :位圖像素(寬)
-----------------------------------------------------------------------*/
void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,unsigned char Pix_x,unsigned char Pix_y)
{
unsigned int i,n;
unsigned char row;
if (Pix_y%8==0)
{
row=Pix_y/8; //計算位圖所占行數
}
else
{
row=Pix_y/8+1;
}
for (n=0;n<row;n++)
{
LCD_set_XY(X,Y);
for(i=0; i<Pix_x; i++)
{
LCD_write_byte(map[i+n*Pix_x], 1);
}
Y++; //換行
}
}
/********************************************************************************************************************/
/*-----------------------------------------------------------------------
LCD_write_byte : 寫數據到LCD
輸入參數:data :寫入的數據;
command :寫數據/命令選擇;
-----------------------------------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
CLEARBIT(LCD_PORT,LCD_CE);// 使能LCD_CE = 0
if (command == 0)
{
CLEARBIT(LCD_PORT,LCD_DC);// 傳送命令 LCD_DC = 0;
}
else
{
SETBIT(LCD_PORT,LCD_DC);// 傳送數據LCD_DC = 1;
}
for(i=0;i<8;i++)
{
if(dat&0x80)
{
SETBIT(LCD_PORT,SDIN);//SDIN = 1;
}
else
{
CLEARBIT(LCD_PORT,SDIN);//SDIN = 0;
}
CLEARBIT(LCD_PORT,SCLK);//SCLK = 0;
dat = dat << 1;
SETBIT(LCD_PORT,SCLK);//SCLK = 1;
}
SETBIT(LCD_PORT,LCD_CE);//LCD_CE = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -