《基于AVR的绘图型12864图形库.doc》由会员分享,可在线阅读,更多相关《基于AVR的绘图型12864图形库.doc(30页珍藏版)》请在金锄头文库上搜索。
1、基于AVR的绘图型12864图形库文件#ifndef _avr_huitu12864_h#define _avr_huitu12864_h#include #include #define uchar unsigned char #define uint unsigned int #define RS (10) /控制口PC口;数据口是PA口#define RW (11)#define EN (12)#define CS1 (13)#define CS2 (14)#define REST (15)void wr_data(uchar dat); /写数据void wr_command(ucha
2、r command); /写指令void qingping(uchar cs); /清屏void wr_onebytel(uchar x, uchar y, uchar dat); /在第X页Y列写一字节数据void rd_data(void); /读数据void rd_onebytel(uchar x,uchar y); /在第X页Y列读一字节数据void rd_somebytel(uchar x,uchar y,uchar z); / 从第X页Y列开始读Z字节数据void point(uchar x,uchar y,uchar zheng); /在第X行Y列写一个点(zheng=1时表示点
3、亮,0表示熄灭;0=X=63,0=Yx,yyyvoid line(uchar x,uchar y,uchar hh,uchar yy,uchar zheng); /从坐标(X,Y)到(XX,YY)画一条线zheng=1点亮 0熄灭;void biankuang(uchar x,uchar y,uchar xx,uchar yy,uchar kuan,uchar zheng);/从坐标(X,Y)到(XX,YY)画一个矩形边框,kuan表示边框宽度;zheng=1点亮 0熄灭;xxx,yyyvoid yuan(uchar x,uchar y,char r,uchar zheng); /以(X,Y)
4、为圆心R为半径画圆面,zheng=1点亮 0熄灭void yuanbiankuang(uchar x,uchar y,char r,uchar kuan,uchar zheng);/以(X,Y)为圆心R为半径画圆边框,kuan表示宽度,zheng=1点亮 0熄灭void fanxian(uchar x,uchar y,uchar xx,uchar yy); /从坐标(X,Y)到(XX,YY)的矩形区域内数据反显void pointf(uchar x,uchar y); /点(X,Y)反显void yuanfanxian(uchar x,uchar y,char r); /以(X,Y)为圆心R为
5、半径圆形区域内数据反显uchar rd_point(uchar x,uchar y); /读(X,Y)点得数据 (返回值为uchar型)void wr_sin(uchar a,uchar b,uchar c,uchar d); /画函数正弦曲线,起始坐标为(A,0)b表示最大值,c表示频率,d=1点亮 0熄灭void wr_cos(uchar a,uchar b,uchar c,uchar d); /画函数余弦曲线,起始坐标为(A,0)b表示最大值,c表示频率,d=1点亮 0熄灭void wr_tan(uchar a,uchar b,uchar c,uchar d); /画函数正切曲线,起始坐
6、标为(A,0)b表示最大值,c表示频率,d=1点亮 0熄灭void taiji(uchar x,uchar y,char r); /以(X,Y)为圆心R为半径画一个太极图void lcd_busy(void); /判忙void lcd_init(void); /LCD初始化void init(void); /初始化uchar read_dat; uchar rd_zhanchun;void delay_5us(uint n)for(;n0;n-);void delay_ms(uint n) uint i; for(;n0;n-) for(i=0;i7)=0) flag = 0;void lcd
7、_init(void) qingping(2); wr_command(0x3e);wr_command(0xc0);wr_command(0xb8);wr_command(0x40);wr_command(0x3f);void qingping(uchar cs)unsigned char i, j;switch(cs) case 0: PORTC |= CS1; PORTC &= CS2; ;break; case 1 : PORTC &= CS1; PORTC |= CS2; ;break;case 2: PORTC |= CS1; PORTC |= CS2; ;break; for(j
8、 = 0; j 8; j+) wr_command(0xb8 + j);wr_command(0x40);for(i = 0; i 64; i+) wr_data(0x00); void wr_onebytel(uchar x, uchar y, uchar dat)if(y 64) PORTC|=CS1; PORTC&=CS2;/左半屏else y -= 64; PORTC &= CS1; PORTC |= CS2; /右半屏wr_command(0xc0);/起始行地址wr_command(0xb8 + x);/页地址wr_command(0x40 + y);/列地址0-63wr_data
9、(dat);void rd_data(void) DDRA=0x00;PORTA=0xff;PORTC|=RS;/数据PORTC|=RW;/读出PORTC|=EN;delay_5us(4);read_dat=PINA;/数据 delay_5us(4);PORTC &= EN;DDRA=0xff;PORTA=0xff;void rd_onebytel(uchar x,uchar y) if(y 64) PORTC|=CS1; PORTC&=CS2;/左半屏else y -= 64; PORTC &= CS1; PORTC |= CS2; /右半屏wr_command(0xc0);/起始行地址wr
10、_command(0xb8 + x);/页地址wr_command(0x40 + y);/列地址0-63rd_data();/读空rd_data();void rd_somebytel(uchar x,uchar y,uchar z) uchar i; rd_data();/读空 for(i=0;iz;i+) rd_onebytel(x,y+i);rd_zhanchuni=read_dat; void point(uchar x,uchar y,uchar zheng) uchar xieru,zuhe; if(y 64) PORTC|=CS1; PORTC&=CS2;/左半屏else y -= 64; PORTC &= CS1; PORTC |= CS2; /右半屏 wr_command(0xc0);/起始行地址 wr_command(0xb8 + x/8);/页地址 wr_command(0x40 + y);/列地址0-63 rd_data();/读空 rd_data(); if(zheng=1