?? lcd12864_st7920.h
字號(hào):
/*********************************************************************
網(wǎng)上收集: 免費(fèi)共享:慧凈電子
目 的: 建立xxxx操作庫(kù)
目標(biāo)系統(tǒng): 基于任何兼容AVR的微處理器
應(yīng)用軟件: ICC
版 本: Version 2.0
收集時(shí)間: 2008-08-08
開(kāi)發(fā)人員: 慧凈網(wǎng)上收集整理(感謝能放在網(wǎng)上共享的朋友們,功德無(wú)量,有你們,中國(guó)會(huì)更強(qiáng)大)
說(shuō) 明: 版權(quán):慧凈助學(xué)產(chǎn)品(包括程序源碼,硬件資源)沒(méi)有版權(quán),歡迎復(fù)制共享,功德無(wú)量,為中國(guó)自動(dòng)化與單片事業(yè)作一點(diǎn)功勞。部分源碼技術(shù)資料、軟件、來(lái)源網(wǎng)絡(luò),如有傷害到你的利益請(qǐng)來(lái)郵:hjmcu@163.com 我們的助學(xué)會(huì)員會(huì)定期刪除,謝謝你的理解與支持。
助學(xué)小店:http://shop37031453.taobao.com/
慧凈空間:http://hi.baidu.com/hjmcu
助學(xué)QQ: 121350852
*********************************************************************/
/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新記錄:
----------------------------------------------------------------------
入口參數(shù)說(shuō)明:
//#define OUT_LCD_CS sbi(DDRD,0)
//#define SET_LCD_CS sbi(PORTD,0)
//#define CLR_LCD_CS cbi(PORTD,0)
----------------------------------------------------------------------
待定參數(shù)說(shuō)明:
----------------------------------------------------------------------
對(duì)外變量說(shuō)明:
----------------------------------------------------------------------
對(duì)外函數(shù)說(shuō)明:
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
/*--------------------------------------------------------------------
接口定義:
LCD12864_ST7920 ATmega16
1.GND -------- GND
2.VCC -------- VCC
3.V0 -------- V0
4.RS(CS) -------- VCC
5.R/W(SID) -------- MOSI/PB5
6.E(SCLK) -------- SCK/PB7
7.D0 -------- NC
8.D1 -------- NC
9.D2 -------- NC
10.D3 -------- NC
11.D4 -------- NC
12.D5 -------- NC
13.D6 -------- NC
14.D7 -------- NC
15.PSB -------- GND
16.NC -------- NC
17.RST -------- NC
18.NC -------- NC
19.LED+ -------- VCC
20.LED- -------- GND
說(shuō)明:
(1)使用ATmega16的硬件SPI操作LCD12864_ST7920
(2)PIN4/CS接VCC,其實(shí)也可接到特定的IO口,但外部程序需要指定
--------------------------------------------------------------------*/
#ifndef LCD12864_ST7920_H
#define LCD12864_ST7920_H
#include "D:\ICC_H\CmmIcc.h"
void SPI_init()
{
DDRB |= 0xB0;
SPCR = 0x50; //setup SPI
SPSR = 0x01; //setup SPI
SEI();
}
void lcd_wrByte(uint8 data)
{
SPDR = data;
while ((SPSR & 0x80) == 0);
}
void lcd_wrCmd(uint8 HC,uint8 LC)
{
lcd_wrByte(0xF8);
lcd_wrByte(HC); //傳輸高四位
lcd_wrByte(LC); //傳輸?shù)退奈?}
void lcd_wrDat(uint8 HD,uint8 LD)
{
lcd_wrByte(0xFA);
lcd_wrByte(HD); //傳輸高四位
lcd_wrByte(LD); //傳輸?shù)退奈?}
/*
x表示在第幾行顯示,y表示在第幾列顯示
*/
void lcd_set_xy(uint8 x,uint8 y)
{
uint8 adr;
switch(x)
{
case 1: adr = 0x7F + y;
break; //在第1行y列顯示
case 2: adr = 0x8F + y;
break; //在第2行y列顯示
case 3: adr = 0x87 + y;
break; //在第3行y列顯示
case 4: adr = 0x97 + y;
break; //在第4行y列顯示
default: ;
}
lcd_wrCmd(adr&0xF0,(adr&0x0F)<<4);
}
void lcd_putc(uint8 x,uint8 y,uint8 ch)
{
lcd_set_xy(x,y);
delay50us(20);
lcd_wrDat(ch&0xF0,(ch&0x0F)<<4);
}
void lcd_putd0(uint8 x,uint8 y,uint32 dat,uint8 length)
{
sint8 i;
speaData(dat,length);
lcd_set_xy(x,y);
delay50us(40);
for(i=length-1;i>=0;i--)
{
lcd_wrDat( (dataElem[i]+0x30)&0xF0 ,( (dataElem[i]+0x30)&0x0F )<<4 );
delay50us(40);
}
}
void lcd_putd(uint8 x,uint8 y,uint32 dat,uint8 length)
{
sint8 i;
sint8 effectLen;
if(dat>999999)
effectLen=7;
else if(dat>99999)
effectLen=6;
else if(dat>9999)
effectLen=5;
else if(dat>999)
effectLen=4;
else if(dat>99)
effectLen=3;
else if(dat>9)
effectLen=2;
else
effectLen=1;
speaData(dat,effectLen);
lcd_set_xy(x,y);
delay50us(40);
if(length>effectLen)
{
for(i=length-effectLen-1;i>=0;i--)
{
lcd_wrDat(' '&0xF0,(' '&0x0F)<<4);
delay50us(40);
}
}
for(i=effectLen-1;i>=0;i--)
{
lcd_wrDat( (dataElem[i]+0x30)&0xF0 ,( (dataElem[i]+0x30)&0x0F )<<4 );
delay50us(40);
}
}
void lcd_puts(uint8 x,uint8 y,uint8 *str)
{
lcd_set_xy(x,y);
delay50us(20);
while(*str)
{
lcd_wrDat((*(str))&0xF0,((*(str))&0x0F)<<4);
str++;
delay50us(20);
}
}
void lcd_puts_(uint8 x,uint8 y,uint8 *str,uint8 dlyMs)
{
lcd_set_xy(x,y);
delay50us(20);
while(*str)
{
lcd_wrDat((*(str))&0xF0,((*(str))&0x0F)<<4);
str++;
delay50ms(dlyMs);
}
}
void lcd_clr()
{
lcd_wrCmd(0x00,0x10);
delay50us(200);
}
void lcd_init(void)
{
SPI_init();
//OUT_LCD_CS; //若LCD_CS
//SET_LCD_CS;
delay50ms(1);
lcd_wrCmd(0x30,0x30); //使用8位控制界面,使用基本指令集
//lcd_wrCmd(0x00,0xF0); //整體顯示ON
lcd_wrCmd(0x00,0xC0); //整體顯示ON
lcd_wrCmd(0x00,0x10); //清屏
//lcd_wrCmd(0x10,0x00); //光標(biāo)
lcd_wrCmd(0x00,0x60);
//lcd_wrCmd(0x00,0x70); //顯示右移
delay50ms(1); //不可省去!!!
}
#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -