📄 hanz.i
字号:
// 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
// Needed by the power management functions (sleep.h)
#asm
#ifndef __SLEEP_DEFINED__
#define __SLEEP_DEFINED__
.EQU __se_bit=0x40
.EQU __sm_mask=0xB0
.EQU __sm_powerdown=0x20
.EQU __sm_powersave=0x30
.EQU __sm_standby=0xA0
.EQU __sm_ext_standby=0xB0
.EQU __sm_adc_noise_red=0x10
.SET power_ctrl_reg=mcucr
#endif
#endasm
//约定page1(即0X12寄存器为0XB1选择操作图层为page1)为文本层
//,page2(0XB2选择操作图层为page2)为图层
//0X00寄存器为0XC5时为图层,为0XCD时为文本层,每次调用函数时选择要用的层面,
//调用完后并不返回,初始化时为文本层。
// 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.
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
/*
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
// CodeVisionAVR C Compiler
// (C) 1998-2007 Pavel Haiduc, HP InfoTech S.R.L.
// Prototypes for string functions
#pragma used+
char *strcat(char *str1,char *str2);
char *strcatf(char *str1,char flash *str2);
char *strchr(char *str,char c);
signed char strcmp(char *str1,char *str2);
signed char strcmpf(char *str1,char flash *str2);
char *strcpy(char *dest,char *src);
char *strcpyf(char *dest,char flash *src);
unsigned int strlenf(char flash *str);
char *strncat(char *str1,char *str2,unsigned char n);
char *strncatf(char *str1,char flash *str2,unsigned char n);
signed char strncmp(char *str1,char *str2,unsigned char n);
signed char strncmpf(char *str1,char flash *str2,unsigned char n);
char *strncpy(char *dest,char *src,unsigned char n);
char *strncpyf(char *dest,char flash *src,unsigned char n);
char *strpbrk(char *str,char *set);
char *strpbrkf(char *str,char flash *set);
char *strrchr(char *str,char c);
char *strrpbrk(char *str,char *set);
char *strrpbrkf(char *str,char flash *set);
char *strstr(char *str1,char *str2);
char *strstrf(char *str1,char flash *str2);
char *strtok(char *str1,char flash *str2);
unsigned int strlen(char *str);
void *memccpy(void *dest,void *src,char c,unsigned n);
void *memchr(void *buf,unsigned char c,unsigned n);
signed char memcmp(void *buf1,void *buf2,unsigned n);
signed char memcmpf(void *buf1,void flash *buf2,unsigned n);
void *memcpy(void *dest,void *src,unsigned n);
void *memcpyf(void *dest,void flash *src,unsigned n);
void *memmove(void *dest,void *src,unsigned n);
void *memset(void *buf,unsigned char c,unsigned n);
unsigned int strcspn(char *str,char *set);
unsigned int strcspnf(char *str,char flash *set);
int strpos(char *str,char c);
int strrpos(char *str,char c);
unsigned int strspn(char *str,char *set);
unsigned int strspnf(char *str,char flash *set);
#pragma used-
#pragma library string.lib
/* CodeVisionAVR C Compiler
Prototypes for standard library functions
(C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
*/
#pragma used+
int atoi(char *str);
long int atol(char *str);
float atof(char *str);
void itoa(int n,char *str);
void ltoa(long int n,char *str);
void ftoa(float n,unsigned char decimals,char *str);
void ftoe(float n,unsigned char decimals,char *str);
void srand(int seed);
int rand(void);
void *malloc(unsigned int size);
void *calloc(unsigned int num, unsigned int size);
void *realloc(void *ptr, unsigned int size);
void free(void *ptr);
#pragma used-
#pragma library stdlib.lib
//--------------------------------------------
//送一帧数据
void post_msg(unsigned char msg)
{
DDRA =0xFF; //数据方向输出
PORTA =msg; //输出数据
PORTD.6 =1; //置数据通道
PORTD.5 =0; //选中外设
PORTD.3 =0; //外地址写数据开始
PORTD.3 =1; //写结束
delay_us(3); //延迟等待
PORTD.5 =1; //关外设
}
//送一帧命令
void send_com(unsigned char addr,unsigned char data)
{
PORTA =addr; //输出数据 //地址
PORTD.6 =0; //置命令通道
PORTD.5 =0; //选中外设 //可以接受指令
PORTD.3 =0; //外地址写数据开始 //低电位动作
PORTD.3 =1; //写结束
delay_us(3); //延迟等待
PORTD.5 =1; //关外设
PORTA =data; //输出数据 //指令
PORTD.6 =0; //置命令通道
PORTD.5 =0; //选中外设
PORTD.3 =0; //外地址写数据开始
PORTD.3 =1; //写结束
delay_us(3); //延迟等待
PORTD.5 =1; //关外设
}
//读一帧数据
unsigned char read_com(unsigned char addr)
{
unsigned char temp;
PORTA =addr; //输出数据
PORTD.6 =0; //置命令通道
PORTD.5 =0; //选中外设
PORTD.3 =0; //外地址写数据开始
PORTD.3 =1; //写结束
delay_us(3); //延迟等待
PORTD.5 =1; //关外设
DDRA =0x00;
PORTA =0xFF;
PORTD.6 =1;
PORTD.5 =0;
PORTD.4 =0;
PORTD.4 =1;
delay_us(3);
temp=PINA ;
PORTD.5 =1;
DDRA =0xFF;
return(temp); //PINC
}
void LCD_INIT()
{
DDRD.3 =1;
DDRD.4 =1;
DDRD.5 =1;
DDRD.6 =1;
DDRD.0 =1;
DDRA =0xFF; //输出允许
PORTD.5 =1;
PORTD.3 =1;
PORTD.6 =1;
PORTD.4 =1;
PORTD.0 =0;
delay_ms(300);
PORTD.0 =1;
send_com(0x00,0xCD); //WLCR:电源正常模式,进入文本模式,屏幕开启,屏幕不闪烁,正向显示
send_com(0x01,0x03); //MISC:CLKOUT禁止,BUSY高电平触发,12MHz频率
send_com(0x02,0x00); //APSR:ROM/RAM30ns读取速度,禁止ROM直读,开机滚动复位禁止
send_com(0x03,0x80); //ADSR:显示数据正序,水平,垂直卷动效显禁止
send_com(0x10,0x6F); //?WCCR:读DDRAM定地址,写自加,中英文对齐,正向存储,字体正常粗细,光标ON,闪烁
send_com(0x11,0x10); //DWLR:光标高度2Px,行距设定2Px
send_com(0x12,0xB3); //操作图层 同时两层图层
//MAMR:图形方式光标先水平移动后垂直移动,两层或显示,图层1/2运行,灰度显示
send_com(0x20,0x1D); //AWRR:设定右边视窗位置
send_com(0x21,0x1D); //DWRR:设定右边显示位置(=240/8-1)
send_com(0x30,0x7F); //AWBR:设定底部视窗位置
send_com(0x31,0x80); //DWBR:设定底部显示位置(=128-1)
send_com(0x40,0x00); //AWLR: 设定左边视窗位置
send_com(0x41,0x00); //DWLR: 设定左边显示位置(0x00)
send_com(0x50,0x00); //AWTR: 设定上部视窗位置
send_com(0x51,0x00); //DWTR: 设定上部显示位置(0x00)
send_com(0x60,0x00); //CPXR: 设定光标X坐标
send_com(0x70,0x00); //CPYR: 设定光标Y坐标
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -