?? lcd.c
字號:
//typedef unsigned short unsigned int ;
//typedef unsigned int unsigned int ;
//typedef unsigned char unsigned char ;
#include "LCD.h"
#include "Board.h"
#include "lcd_mask_chinese.h"
#include "clock.h"
extern int get_charactor_dots_size(void); //獲取當前漢字字庫的大小
//extern TYPE_CCT_TM clock_time; //用來存放當前系統(tǒng)時間
extern TYPE_CH_DOTS charactor_dots[]; //漢字庫
extern char ASC_MSK[96*12]; //字符庫
extern unsigned char GB_16[4*32];//ls 臨時的字庫 為調試用的
unsigned char gCurRow,gCurCol;
unsigned char gPage_addr,gPhysics_col;
/***********************************************************/
//open the back light
/**********************************************************/
lcd_EnLight( )
{
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB9); //enable backlignt
return 1;
}
/*********************************************************/
//close the back light
/*********************************************************/
lcd_DisLight( )
{
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB9); //Disabke backlignt
return 1;
}
/*************************************************************/
//返回光標所在的行號
/**************************************************************/
unsigned int fnGetRow(void)
{
return gCurRow;
}
/*************************************************************/
//返回光標所在的列號
/**************************************************************/
unsigned int fnGetCol(void)
{
return gCurCol;
}
/*************************************************************/
//廷時
/**************************************************************/
void lcd_delay(unsigned int nnn)
{
unsigned int mmm;
while(nnn-->0)
for(mmm=0;mmm<1000;mmm++)
{ }
}
/*************************************************************/
//寫命令
/**************************************************************/
void wcomd(unsigned char cdat)
{
unsigned int ic;
int Bit ;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK=0;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0); // RS=0;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); // CS=0;
for(ic = 0; ic < 8; ic++)
{
Bit = cdat >> (7 - ic) & 0x01;
if ( Bit == 1 )
{
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=1 ;
}
else
{
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=0;
}
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK=1;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK=0;
}
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); // CS=1;
}
/*************************************************************/
//寫數據
/**************************************************************/
void wdata(unsigned char ddat)
{
unsigned int id;
int Bit ;
if( gPhysics_col < 127)
{
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA = 0;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK = 0;
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0); // RS = 1;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); // CS = 0;
for(id = 0; id < 8; id++)
{
Bit = ddat >> (7 - id) & 0x01;
if ( Bit == 1 )
{
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=1 ;
}
else
{
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=0;
}
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK=1;
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); // SCK=0;
}
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); // CS=1;
//gPhysics_col++;
}
}
/************************************************************************/
//設置熱物理頁碼號和熱處理列號
/************************************************************************/
void set_pos(unsigned char uPage, unsigned char uPhysics_col)
{
unsigned char temp;
if( uPage < 12 && uPhysics_col < 128)
{
wcomd(uPage + 0xb0);//set page address
temp = uPhysics_col & 0x7F;
temp = temp >> 4;
temp = temp | 0x10;
wcomd(temp); //set col MSB
temp = uPhysics_col & 0x0F;
wcomd(temp); //set col LSB
gPage_addr = uPage;
gPhysics_col = uPhysics_col;
}
}
/*************************************************************/
//設置光標
/**************************************************************/
void set_cursor(unsigned int uUser_row, unsigned int uUser_col)
{
if (uUser_row < 6 && uUser_col < 16)
{
set_pos(uUser_row * 2, uUser_col * 8);
gCurRow = uUser_row;
gCurCol = uUser_col;
}
}
/*************************************************************/
//全部為亮或才全部為暗
//當d1 為0xff時顯示器上所有的點就全部為亮
//當d1 為0x00時顯示器上所有的點就全部為暗
/**************************************************************/
void disp_all(unsigned int d1)
{
unsigned int i,j;
for(j=0;j<12;j++)
{
wcomd(0xb0+j);
wcomd(0x10);
wcomd(0x00);
for(i=0;i<64;i++)
{
wdata(d1);//每一個點得寫兩次才行
wdata(d1);
wdata(d1);
wdata(d1);
}
}
}
/********************************************************************/
//清屏
//
/********************************************************************/
int lcd_ClearScreen(void)
{
disp_all(0x00); //0x00 讓每一個點陣都為暗
set_cursor(0,0); //把光標設置在(0,0)這個位置
return 0;
}
/*************************************************************/
//夜晶初始化
/**************************************************************/
int lcd_init()
{
//配置輸出
AT91F_PIO_CfgOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0|AT91C_PIO_PB1|AT91C_PIO_PB2 |AT91C_PIO_PB3 | AT91C_PIO_PB4 | AT91C_PIO_PB9);
lcd_DisLight( );
//復位重啟鍵,廷時一會,然后重啟
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB2); // RST=0;
lcd_delay(3);
AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB2); // RST=1;
//display duty select
wcomd(0x48);
wcomd(0x60); //1/96duty
/*************************************************/
//ADC select
//SEG bi-directional selection
//0xa0:normal direction
//0xa1:reverse direction
/***********************************************/
// wcomd(0xa1); //s0 - s127 //closed by ChengDong Lu at 03/09/2006
wcomd(0xa0);//added by ChengDong Lu at 03/09/2006
/************************************************/
//SHL select
//COM bi-directional selection
//0xc0:normal direction
//0xc8:reverse direction
/***********************************************/
wcomd(0xc8); //c0 - c127
//com0 register select
wcomd(0x44);
wcomd(0x10); //start from com0
//////// set lcd operating voltage//////////
//oscillator on start
wcomd(0xab);
//dc-dc step_up register select
wcomd(0x67); //6 times boosting circuit(64-3times,65-4times,66-5times)
//regulator register select
wcomd(0x27); //(20-27): 1+(rb/ra)=2.3~7.2
//set electronic volume register(select a from 0 to 63)
wcomd(0x81);
wcomd(0x24); //(0~3f)
//lcd bias select register
wcomd(0x56); //1/11
wcomd(0x93);
//lcd grap_scale set up
wcomd(0x8f);
wcomd(0xff);
//power control
wcomd(0x2c); //internal voltage converter circuit is on
lcd_delay(2);
wcomd(0x2e); //internal voltage regulator ciruit is on
lcd_delay(2);
wcomd(0x2f); //internal voltage follower circuit is on
lcd_delay(2);
wcomd(0xaf); //turns display on
lcd_ClearScreen(); //清屏
return 0;
}
/********************************************************************/
//功能: 請除某一行
// row為當前要清除的行
/********************************************************************/
int lcd_ClearLine(int row)
{
unsigned char j , k;
if(row >=0 && row <6)
{
for(j=0;j<2;j++)
{
set_pos(row * 2 + j , 0);
for(k = 0; k < 64; k++)
{
wdata(0x00);
wdata(0x00);
wdata(0x00);
wdata(0x00);
}
}
set_cursor(row,0); //將光標設置在當前清除的行上.
return 1;
}
return 0;
}
/********************************************************************/
//功能: 在顯示器上打印字符
// str指向字符的顯示矩陣
// reverse 為是否為反顯
/********************************************************************/
void print_character(unsigned char * str,int reverse)
{
unsigned char j,k;
if(gCurCol >= 16)
{
gCurCol = 0;
gCurRow++;
}
if(gCurRow >= 6)
{
gCurRow = 0;
}
set_cursor(gCurRow,gCurCol); //設置光標
for(j=0;j<2;j++)
{
set_pos(gCurRow * 2 + j , gCurCol * 8);
if( reverse == 0)//正顯
{
for(k = 0; k < 8; k++)
{
wdata(str[j*8 +k]);
wdata(str[j*8 +k]);
}
}
else if (reverse == 1)//反顯
{
for(k = 0; k < 8; k++)
{
wdata(~str[j*8 +k]);
wdata(~str[j*8 +k]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -