?? lcd.c
字號:
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <util/delay.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/twi.h>
prog_char LCM_0808[]=
{
/*-- 調入了一幅圖像:D:\ubbmp\du.bmp --*/
/*-- 寬度x高度=8x8 --*/
0x3C,0x7E,0xE7,0xC3,0xC3,0xE7,0x7E,0x3C,
};
prog_char LCM_0840[]=
{
/*-- 調入了一幅圖像:D:\ubbmp\dian.bmp --*/
/*-- 寬度x高度=8x40 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x3E,
0x3E,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00,
};
unsigned char SYSTAB[8]={0x30,0x87,0x07,0x27,0x42,0xF0,0x28,0x00};
unsigned char SCRTAB[10]={0x00,0x00,0xf0,0x80,0x25,0xf0,0x00,0x00,0x00,0x00};
void sed1335_write_command(unsigned char commandcode)
{//寫命令//
bitset(PORTG,__lcd_a0);
bitset(PORTD,__lcd_rd);
bitclr(PORTG,__lcd_wr);
PORTC=commandcode;
bitset(PORTG,__lcd_wr);
}
void sed1335_write_data(unsigned char data)
{//寫數據//
bitclr(PORTG,__lcd_a0);
bitset(PORTD,__lcd_rd);
bitclr(PORTG,__lcd_wr);
PORTC=data;
bitset(PORTG,__lcd_wr);
}
unsigned char asc_lcd(unsigned char ch)
{//將實際的字符轉換為LCD能顯示的字符
if(ch<10) ch+=48;
return ch;
}
void Lcd_Init(void)
{//初始化函數//
unsigned char i;
PORTC = 0x00; //lcd數據口,輸出
DDRC = 0xFF; //11111111
bitset(DDRD,__lcd_rd);
bitset(DDRG,__lcd_wr);
bitset(DDRG,__lcd_a0); //以上為液晶屏用輸出口
sed1335_write_command(0x40); /* 1SYSTEM SET代碼40 */
for(i=0;i<8;i++)
{
sed1335_write_data(SYSTAB[i]); /* 寫入參數 */
}
delay_us(10);
sed1335_write_command(0x44); /* 2SCROLL代碼 44*/
for(i=0;i<10;i++)
{
sed1335_write_data(SCRTAB[i]); /* 寫入參數 */
}
delay_us(10);
sed1335_write_command(0x5a); /* 3HDOT SCR 代碼 5a*/
sed1335_write_data(0X00); /* 設置參數P1 */
delay_us(10);
sed1335_write_command(0x5b); /* 4OVLAY 代碼 5b*/
sed1335_write_data(0x01); /* 設置參數:顯示一,三區為圖形屬性,合成方式為異或方式 */
delay_us(10);
sed1335_write_command(0x4c); /* 5CSRDIR 代碼 4c*/
delay_us(10);
Lcd_Clear(); /* 調清屏函數 */
delay_us(10);
sed1335_write_command(0x59); /* 6顯示狀態設置 */
sed1335_write_data(0X14); /* 設置參數:顯示一二區關光標 */
delay_us(10);
}
void Lcd_Clear(void)
{//清屏函數//
unsigned int i;
sed1335_write_command(0x46); /* CSRW 代碼 */
sed1335_write_data(0X00); /* 設置參數光標指針低8位 */
sed1335_write_data(0X00); /* 設置參數光標指針高8位 */
sed1335_write_command(0x42); /* MWRITE 代碼 42*/
for(i=0;i<9600;i++) //
{
sed1335_write_data(0x20); /* 寫入數據 */
}
for(i=0;i<9600;i++) //
{
sed1335_write_data(0x00); /* 寫入數據 */
}
}
void Cur_Set(unsigned int Ox,unsigned int Oy, unsigned char attribs)
{//光標設置//ox,oy:液晶屏上的位置,attribs為是否為非一區
unsigned int temp;
temp = Oy*DB+Ox;
if(attribs) temp += BasePart1; // 如果需要就指向第二區,加上第二區首地址
sed1335_write_command( CsrW ); // 光標Locate,定位
sed1335_write_data( (unsigned char)(temp & 0xff) );// 寫入參數CSRL設置參數光標指針低8位
sed1335_write_data( (unsigned char)(temp /256 ) ); // 寫入參數CSRH設置參數光標指針高8位
}
void Lcd_Rect(unsigned int Ox,unsigned int Oy,unsigned int Rect_Long,unsigned int Rect_High,unsigned char sign)
{//ox,oy:液晶屏上的位置,Rect_Long:線的長度,Rect_High:線的高度,sign反顯標志。
unsigned int Optr,last_tmp,tempCount1,tempCount2;
unsigned char tempchar;
//確定最后一個字節要寫的數據
last_tmp=0x00;
tempCount2=Rect_Long%8;
for(tempCount1=7;tempCount1>7-tempCount2;tempCount1--)
{
bitset(last_tmp,tempCount1);
}
//////////////////////////////////////////////////////////////////////
Optr = Oy * DB + Ox + BasePart1 ; //起始內存位置
tempchar=0;
for(tempCount1=0;tempCount1<Rect_High;tempCount1++)
{
sed1335_write_command(CsrW); //光標定位指令
sed1335_write_data((unsigned char)(Optr &0xff)); //設置光標地址CSR
sed1335_write_data((unsigned char)(Optr /256 ));
sed1335_write_command(mWrite); //ram寫指令
for(tempCount2=0;tempCount2<Rect_Long/8;tempCount2++)
{
tempchar=0xff;
if(sign==1) tempchar=0xff-tempchar;
sed1335_write_data(tempchar);
}
if(last_tmp!=0)
{
tempchar=last_tmp;
if(sign==1) tempchar=0xff-tempchar;
sed1335_write_data(tempchar);
}
Optr+=DB;
}
}
void Lcd_Char(unsigned int Ox,unsigned int Oy,unsigned char Count,unsigned char *buf)
{//ox,oy:液晶屏上的位置,Count:要顯示的字符數量,*buf:要顯示字符所在的數組。
unsigned int tempCount1,Optr;
unsigned char tempchar;
Optr = Oy * DB + Ox; //起始內存位置
sed1335_write_command(CsrW); //光標定位指令
sed1335_write_data((unsigned char)(Optr &0xff)); //設置光標地址CSR
sed1335_write_data((unsigned char)(Optr /256 ));
sed1335_write_command(mWrite); //ram寫指令
tempchar=0;
for (tempCount1=0;tempCount1<Count;tempCount1++)
{
tempchar=asc_lcd(buf[tempCount1]);
sed1335_write_data(tempchar);
}
}
void Lcd_Graph(unsigned int Ox,unsigned int Oy,unsigned int Cnumber,unsigned char width,unsigned char high,unsigned char sign)
{//ox,oy:液晶屏上的位置,Cnumber:數組中的位置,width,high,圖形的寬高,sign反顯標志。
unsigned int tempPtr,Optr;
unsigned int tempCount1,tempCount2,nByte;
unsigned char tempchar;
nByte = width/8; //列數
Optr = Oy * DB + Ox + BasePart1 ; //起始內存位置
tempPtr = Cnumber*high*nByte; //數組起始位置
tempchar=0;
for (tempCount1=0;tempCount1<high;tempCount1++)
{
sed1335_write_command(CsrW); //光標定位指令
sed1335_write_data((unsigned char)(Optr &0xff)); //設置光標地址CSR
sed1335_write_data((unsigned char)(Optr /256 ));
sed1335_write_command(mWrite); //ram寫指令
for(tempCount2=0;tempCount2<nByte;tempCount2++)
{
switch(width)
{
case 8:
if(high==8) tempchar=pgm_read_byte_near(LCM_0808+tempPtr);
if(high==40) tempchar=pgm_read_byte_near(LCM_0840+tempPtr);
break;
case 16:
tempchar=pgm_read_byte_near(LCM_1640+tempPtr);
break;
case 32:
tempchar=pgm_read_byte_near(LCM_3240+tempPtr);
break;
case 40:
if(high==18) tempchar=pgm_read_byte_near(LCM_4018+tempPtr);
if(high==36) tempchar=pgm_read_byte_near(LCM_4036+tempPtr);
if(high==8) tempchar=pgm_read_byte_near(LCM_4008+tempPtr);
break;
case 48:
tempchar=pgm_read_byte_near(LCM_4880+tempPtr);
break;
case 56:
if(high==80) tempchar=pgm_read_byte_near(LCM_5680+tempPtr);
if(high==40) tempchar=pgm_read_byte_near(LCM_5640+tempPtr);
break;
case 72:
tempchar=pgm_read_byte_near(LCM_72120+tempPtr);
break;
case 96:
tempchar=pgm_read_byte_near(LCM_9680+tempPtr);
break;
case 112:
tempchar=pgm_read_byte_near(LCM_11280+tempPtr);
break;
}
if(sign==0) tempchar=0xff-tempchar;
sed1335_write_data(tempchar); //寫入數據
tempPtr ++;
}
Optr+=DB;
}
}
//////////////////////////////////////////////////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -