?? main.i
字號(hào):
// CodeVisionAVR C Compiler
// (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega16
#pragma used+
sfrb TWBR=0;
sfrb TWSR=1;
sfrb TWAR=2;
sfrb TWDR=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4; // 16 bit access
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRRL=9;
sfrb UCSRB=0xa;
sfrb UCSRA=0xb;
sfrb UDR=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e; // 16 bit access
sfrb UBRRH=0x20;
sfrb UCSRC=0X20;
sfrb WDTCR=0x21;
sfrb ASSR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28; // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a; // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c; // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb SFIOR=0x30;
sfrb OSCCAL=0x31;
sfrb OCDR=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TWCR=0x36;
sfrb SPMCR=0x37;
sfrb TIFR=0x38;
sfrb TIMSK=0x39;
sfrb GIFR=0x3a;
sfrb GICR=0x3b;
sfrb OCR0=0X3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-
// Interrupt vectors definitions
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
// CodeVisionAVR C Compiler
// (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega16
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
/*
CodeVisionAVR C Compiler
Prototypes for mathematical functions
Portions (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.
Portions (C) 2000-2001 Yuri G. Salov
*/
#pragma used+
unsigned char cabs(signed char x);
unsigned int abs(int x);
unsigned long labs(long x);
float fabs(float x);
signed char cmax(signed char a,signed char b);
int max(int a,int b);
long lmax(long a,long b);
float fmax(float a,float b);
signed char cmin(signed char a,signed char b);
int min(int a,int b);
long lmin(long a,long b);
float fmin(float a,float b);
signed char csign(signed char x);
signed char sign(int x);
signed char lsign(long x);
signed char fsign(float x);
unsigned char isqrt(unsigned int x);
unsigned int lsqrt(unsigned long x);
float sqrt(float x);
float floor(float x);
float ceil(float x);
float fmod(float x,float y);
float modf(float x,float *ipart);
float ldexp(float x,int expon);
float frexp(float x,int *expon);
float exp(float x);
float log(float x);
float log10(float x);
float pow(float x,float y);
float sin(float x);
float cos(float x);
float tan(float x);
float sinh(float x);
float cosh(float x);
float tanh(float x);
float asin(float x);
float acos(float x);
float atan(float x);
float atan2(float y,float x);
#pragma used-
#pragma library math.lib
//--------------------------------------------
//****************************************************
//送一幀數(shù)據(jù)
void Post_Msg(unsigned char Msg)
{
DDRC =0xFF;
PORTC =Msg; //輸出數(shù)據(jù)
PORTA.2 =1; //置數(shù)據(jù)通道
PORTB.0 =0; //選中外設(shè)
PORTA.0 =0; //外地址寫(xiě)數(shù)據(jù)開(kāi)始
PORTA.0 =1; //寫(xiě)結(jié)束
PORTB.0 =1; //關(guān)外設(shè)
delay_us(5);
}
void Post_Com(unsigned char Com)
{
DDRC =0xFF;
PORTC =Com; //輸出數(shù)據(jù)
PORTA.2 =0; //置命令通道
PORTB.0 =0; //選中外設(shè)
PORTA.0 =0; //外地址寫(xiě)數(shù)據(jù)開(kāi)始
PORTA.0 =1; //寫(xiě)結(jié)束
PORTB.0 =1; //關(guān)外設(shè)
delay_us(5);
}
//*************************************
//送一幀命令
//*************************************
void Send_Com(unsigned char Addr,unsigned char Data)
{
Post_Com(Addr);
Post_Com(Data);
}
//*************************************************
void Send_Data(unsigned char X0,unsigned char Y0,unsigned char Data,unsigned char Pos)
{
Send_Com(0x12,0xB1+Pos);
Send_Com(0x60,X0);
Send_Com(0x70,Y0*8);
Post_Msg(Data);
}
//========================================
//讀一幀數(shù)據(jù)
//========================================
unsigned char Read_Reg(unsigned char Addr)
{
unsigned char Temp;
Post_Com(Addr);
PORTC =0xFF;
DDRC =0x00;
PORTA.2 =0;
PORTB.0 =0;
PORTA.1 =0;
delay_us(1);
Temp=PINC ;
PORTA.1 =1;
PORTB.0 =1;
delay_us(10);
DDRC =0xFF;
return(Temp);
}
unsigned char Read_Data(unsigned char X0,unsigned char Y0,unsigned char N)
{
unsigned char Temp;
if(N)Send_Com(0x12,0xB2); //存取文本圖層
else Send_Com(0x12,0xB1); //存取圖形圖層
Send_Com(0x60,X0);
Send_Com(0x70,Y0);
PORTC =0xFF;
DDRC =0x00;
PORTA.2 =1;
PORTB.0 =0;
PORTA.1 =0;
delay_us(1);
Temp=PINC ;
PORTA.1 =1;
PORTB.0 =1;
DDRC =0xFF;
return(Temp);
}
void reset_lcd()
{
DDRC =0xFF; //輸出允許
PORTA.0 =1;
PORTA.2 =1;
PORTA.1 =1;
PORTB.0 =0;
PORTB.4=0;
delay_ms(500);
PORTB.4=1;
Send_Com(0x00,0xCD); //WLCR: 電源正常模式,進(jìn)入文本模式,屏幕開(kāi)啟,屏幕不閃爍,正向顯示
Send_Com(0x01,0x03); //MISC: CLKOUT禁止,BUSY高電平觸發(fā),12MHz頻率
Send_Com(0x02,0x00); //APSR: ROM/RAM30ns讀取速度,禁止ROM直讀,開(kāi)機(jī)滾動(dòng)復(fù)位禁止
Send_Com(0x03,0x80); //ADSR: 顯示數(shù)據(jù)正序,水平,垂直卷動(dòng)效顯禁止
Send_Com(0x10,0x2F); //WCCR: 讀DDRAM定地址,寫(xiě)自加,中英文對(duì)齊,正向存儲(chǔ),字體正常粗細(xì),光標(biāo)ON,閃爍
Send_Com(0x11,0x10); //DWLR: 光標(biāo)高度2Px,行距設(shè)定2Px
Send_Com(0x12,0xB3); //MAMR: 圖形方式光標(biāo)先垂直后水平移動(dòng),兩層或顯示,圖層1/2運(yùn)行,灰度顯示
Send_Com(0x20,0x1D); //AWRR: 設(shè)定右邊視窗位置
Send_Com(0x21,0x1D); //DWRR: 設(shè)定右邊顯示位置(=240/8-1)
Send_Com(0x30,0x7F); //AWBR: 設(shè)定底部視窗位置
Send_Com(0x31,0x80); //DWBR: 設(shè)定底部顯示位置(=128-1)
Send_Com(0x40,0x00); //AWLR: 設(shè)定左邊視窗位置
Send_Com(0x41,0x00); //DWLR: 設(shè)定左邊顯示位置(0x00)
Send_Com(0x50,0x00); //AWTR: 設(shè)定上部視窗位置
Send_Com(0x51,0x00); //DWTR: 設(shè)定上部顯示位置(0x00)
Send_Com(0x60,0x00); //CPXR: 設(shè)定光標(biāo)X坐標(biāo)
//Send_Com(0x61,0x00); //BGSG: 顯示區(qū)X位置
Send_Com(0x70,0x00); //CPYR: 設(shè)定光標(biāo)Y坐標(biāo)
Send_Com(0x71,0x00); //BGCM: 設(shè)定水平移動(dòng)模式下移動(dòng)的起始X位置
Send_Com(0x72,0xEF); //EDCM: 設(shè)定水平移動(dòng)模式下移動(dòng)終止X位置
Send_Com(0x80,0x60); //BTMR: 設(shè)置光標(biāo)閃爍頻率
Send_Com(0x81,0x40); //FRCA: 通用寄存器,設(shè)置為0x40(must do that when reset the lcd)
Send_Com(0x90,0x0F); //SCCR: 設(shè)定XCL周期,即刷新頻率,數(shù)值越大,刷新越慢
Send_Com(0xF0,0xA0); //
Send_Com(0xF1,0x0F); //字體大小置
}
//===============================================================
//--清屏函數(shù),將文本層和圖形層全清空
void clear()
{
Send_Com(0x12,0xB3);
Send_Com(0xE0,0x00);
Send_Com(0xF0,0xA8);
delay_ms(100);
}
//===============================================================
/***************************************************************************
x表示的是行(一個(gè)象點(diǎn)),y表示的是列(一個(gè)字符),
daxiao的高4位表示縱向放大倍數(shù),低4位表示橫向放大的倍數(shù)
daxiao表示的是字符放大系數(shù),高四位表示橫向放大,低四位表示縱向放大倍數(shù)
如果不放大的話就默認(rèn)送一個(gè)數(shù)0
1表示1倍,2表示2倍,3表示3倍,4表示4倍
*p表示的是需要送過(guò)來(lái)顯示的漢字字符串
***************************************************************************/
void chinese1(unsigned char X0,unsigned char Y0,unsigned char daxiao,flash unsigned char *p)
{unsigned char temp=0;
temp=daxiao-0x11;//轉(zhuǎn)化為內(nèi)部的實(shí)際寄存器值
daxiao=temp;
daxiao=daxiao<<6;
temp|=0x0f;
temp|=daxiao;
Send_Com(0xf1,temp);//設(shè)定漢字的大小,0倍大小16*16漢字
Send_Com(0xf0,0xa2);//選擇字型ROM轉(zhuǎn)換電路使能,選擇簡(jiǎn)體國(guó)標(biāo)庫(kù),ASCII二區(qū)
Send_Com(0x60,Y0);
Send_Com(0x70,X0*16);
while((*p)>0)
{
Post_Msg(*p);
delay_us(50);
p++;
}
}
void chinese(unsigned char X0,unsigned char Y0,flash unsigned char *p)
{
Send_Com(0xf1,0x0f);//設(shè)定漢字的大小,0倍大小16*16漢字
Send_Com(0xf0,0xa2);//選擇字型ROM轉(zhuǎn)換電路使能,選擇簡(jiǎn)體國(guó)標(biāo)庫(kù),ASCII二區(qū)
Send_Com(0x60,Y0);
Send_Com(0x70,X0*16);
while((*p)>0)
{
Post_Msg(*p);
delay_us(50);
p++;
}
}
/**************************************************************************
x表示行坐標(biāo),每一個(gè)象點(diǎn)表示一行
y表示列坐標(biāo),每一個(gè)字符表示一列,自動(dòng)與字符大小匹配
daxiao表示的是字符放大系數(shù),高四位表示橫向放大,低四位表示縱向放大倍數(shù)
如果不放大的話就默認(rèn)送一個(gè)數(shù)0
p表示需要顯示的字符的ASCII碼,所有的顯示均使用標(biāo)準(zhǔn)ASCII碼
*************************************************************************/
void word1(unsigned char x,unsigned char y,unsigned char daxiao,unsigned char p)
{unsigned char temp=0;
temp=daxiao;
daxiao=daxiao<<6;
temp|=0x0f;
temp|=daxiao;
Send_Com(0xf1,temp);
Send_Com(0xf0,0xa0); //換字符表到表0
Send_Com(0x60,y); //x,y與液晶的實(shí)際地址剛好是反的
Send_Com(0x70,x*8);
Post_Msg(p);
}
void word(unsigned char x,unsigned char y,unsigned char p)
{
Send_Com(0xf1,0x0f);
Send_Com(0xf0,0xa0); //換字符表到表0
Send_Com(0x60,y); //x,y與液晶的實(shí)際地址剛好是反的
Send_Com(0x70,x*8);
Post_Msg(p);
}
//===============================================================
//---顯示字符串,包括中文字符,可混合中英文即符號(hào)
//X0:列設(shè)置(0-29) Y0:行設(shè)置(0-15)
void Show_Text(unsigned char X0,unsigned char Y0,unsigned char *Text)
{
Send_Com(0x12,0xB1); //進(jìn)入文本圖層
Send_Com(0x60,Y0);
Send_Com(0x70,X0*16);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -