NOKIA5110屏幕驱动程序
来源:互联网 发布:卖花茶比较好的淘宝店 编辑:程序博客网 时间:2024/06/05 20:29
虽然今年的单片机比赛已经结束,但我想我还远不会和单片机说拜拜。它是学习硬件知识的最佳选择,虽然我们学它主要是在写程序,但不得不说学习到不少的新知识。有时你会很无奈地说句“硬件这东西。。。”,我想这也正是硬件的魅力。
虽然今年换了比较大型的板子必比赛,用的事TFT彩屏来演示程序,单学习屏幕还是应该晓得最简单点的,像以前使用的NOKIA5110的屏,驱动如下:
NOKIA5110.H文件:
#ifndef __NOKIA5110_H__#define __NOKIA5110_H__#include <reg52.h>#include <string.h>typedef unsigned char uchar;extern uchar Lcd_x,Lcd_y;extern uchar Datas[6][84];sbit N_CS = P1^1; // chip selected.sbit N_RS = P1^0; // reset.sbit N_DC = P1^2; // write data or write command(1/0).sbit N_DI = P1^3; // data in.sbit N_CL = P1^4; // clock.void LcdInit(void); // NOKIA5110 LCD init.void Clear(void); // clear full screen.void WriteByte(uchar dat,bit f_dc); // Write byte, f_dc is flag bit.void SetPos(uchar _x,uchar _y);void PutPixel(uchar _x,uchar _y,uchar f_c);void Line(char x0,char y0,char x1,char y1,uchar f_c);void Rectangle(char x0,char y0,char x1,char y1,char f_c);void Circle(char x0,char y0,char r,uchar f_c);void PutChar(char x0,char y0,char c0);void PutString(char x0,char y0,char* s);uchar GetPixel(char x0,char y0);#endifNOKIA5110.C文件:
#include "NOKIA5110.H"//function's hand define#include "DELAY.H"//delay functions#include "CONSTANT.H"//constantsuchar Lcd_x,Lcd_y;//point's positionuchar Datas[6][84];void LcdInit(void){N_RS = 0;//resetdelayms(10);N_RS = 1;WriteByte(0x21,0);// use expansion directiveWriteByte(0xC6,0);// WriteByte(0x06,0);// temp WriteByte(0x13,0); // 1:48WriteByte(0x20,0); // use base directiveWriteByte(0x0C,0);// normalClear();//Init ClearSetPos(0,0);//Init Position}void WriteByte(uchar dat,bit f_dc){uchar i;N_CS = 0;//open chip selectedN_DC = f_dc;//data selected or command selectedfor(i=0; i<8; i++){ if(dat&0x80) N_DI = 1;//from high bit to low bitelse N_DI = 0;//dat <<= 1;//next bitN_CL = 0; N_CL = 1;//rising edge}N_DI = N_CS = N_DC = 1;//set 1}void SetPos(uchar _x,uchar _y){WriteByte(0x80|_x,0);//set x WriteByte(0x40|_y,0);// set yLcd_x=_x; Lcd_y=_y; //record x and y}void Clear(void)//clear screen{int i = 504;//504 byteSetPos(0,0);while(i--) WriteByte(0x00,1);memset(Datas,0,sizeof(Datas));//record for every point}void PutPixel(uchar _x,uchar _y,uchar f_c){uchar _over = _y%8;//over position_y /= 8;//8 bit for divSetPos(_x,_y);if(f_c) Datas[_y][_x] |= 1 << _over;//judge set or clearelse Datas[_y][_x] &= ~(1 << _over);WriteByte(Datas[_y][_x],1);//do it }void Line(char x0,char y0,char x1,char y1,uchar f_c)// line from (x0,y0) to (x1,y1){char dx,dy,di,dx_x2,dy_x2,dx_sym,dy_sym;dx = x1 - x0;dy = y1 - y0;if(dx > 0) dx_sym = 1;else dx_sym = -1;if(dy > 0) dy_sym = 1;else dy_sym = -1;dx = dx_sym * dx;dy = dy_sym * dy;dx_x2 = dx * 1;dy_x2 = dy * 1;if(dx >= dy){di = dy_x2 - dx;while(x0 != x1){PutPixel(x0,y0,f_c);x0 +=dx_sym;if(di < 0) di += dy_x2;else{di += dy_x2 - dx_x2;y0 += dy_sym;}}}else {di = dx_x2 - dy;while(y0 != y1){PutPixel(x0,y0,f_c);y0 += dy_sym;if(di < 0) di += dx_x2;else{di += dx_x2 - dy_x2;x0 += dx_sym;}}}PutPixel(x0,y0,f_c);}void Circle(char x0,char y0,char r,uchar f_c){//(x0,y0) for thecenter of the circle, r for radiuschar a=0,b=r,di=3-2*r;while(a <= b){PutPixel(x0-b,y0-a,f_c);PutPixel(x0+b,y0-a,f_c);PutPixel(x0-a,y0+b,f_c);PutPixel(x0-b,y0-a,f_c);PutPixel(x0-a,y0-b,f_c);PutPixel(x0+b,y0+a,f_c);PutPixel(x0+a,y0-b,f_c);PutPixel(x0+a,y0+b,f_c);PutPixel(x0-b,y0+a,f_c);a ++;if(di < 0) di += 4 * a + 6;else {di += 10 + 4 * (a - b);b --;}PutPixel(x0+a,y0+b,f_c);}}void Rectangle(char x0,char y0,char x1,char y1,char f_c){Line(x0,y0,x1,y0,f_c); Line(x0,y0,x0,y1,f_c); Line(x1,y0,x1,y1,f_c); Line(x0,y1,x1,y1,f_c);}void PutChar(char x0,char y0,char c0){//give point of left top and put the charchar i, j;if(c0<ascii_begin||c0>=ascii_end) return;for(i=0; i<6; i++){uchar tc=Ascii[c0-ascii_begin][i];for(j=0; j<8; j++){PutPixel(x0+i,y0+j,tc&0x01);tc >>= 1;}}}void PutString(char x0,char y0,char* s){//Put a string, if too long, it will get next line.while(*s){if(x0>78){ x0=0; y0+=8; }PutChar(x0,y0,*s++);x0+=6;}}uchar GetPixel(char x0,char y0)//get give point's message.{return (Datas[y0/8][x0]&(1<<(y0%8)));}
- NOKIA5110屏幕驱动程序
- K60 nokia5110驱动
- nokia5110液晶初始化
- STM32驱动Nokia5110
- 树莓派使用Nokia5110显示屏
- 基于LaunchPad的Nokia5110显示
- NOKIA5110 显示背景黑问题
- 单片机控制NOKIA5110液晶屏之模块化编程
- nokia5110液晶屏显示汉字,图形,…
- Nokia5110液晶屏新手学习笔…
- 51单片机最小系统驱动Nokia5110
- QT编写树莓派的Nokia5110显示屏显示
- 驱动程序
- 驱动程序
- 驱动程序
- 驱动程序
- 驱动程序
- 驱动程序
- 根据customer_id获取最后一个订单中的所有产品
- 没心没肺的忧伤感情日志:也许,你并不知道我也在等你
- HttpsURLConnection 与 HttpURLConnection
- ERP不是管理目标而是管理工具
- Selenium IDE 脚本录制
- NOKIA5110屏幕驱动程序
- WebIM
- 求和
- ORACLE 错误一览表
- 我的第二十一个C++上机报告(贪财的富翁)
- 开源.NET WEBIM
- 成绩分级程序报告
- 各种求和。。。。。各种纠结。。。。。
- 如何获得unix domain socket的对端PID