|
#include <LPC213x.h>
#include "Inc/std.h"
#include "Inc/driver.h"
#define ushort unsigned short
#define uchar unsigned char
#define ulong unsigned long
#define LED 23
#define LCDRS 26
#define LCDRW 27
#define LCDE 25
#define LCDCSL 30
#define LCDCSR 20
void Delay_us(ushort n)
{
ushort i;
for(;n>0;n--)
for (i=0;i<5000;i++);
}
int main()
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
init();
lcdOpen();
lcdStartLine(0);
lcdSetPage(0);
lcdSetRow(0);
pixel(30,20);
pixel(100,50);
pixel(15,40);
pixel(53,57);
pixel(90,36);
pixel(65,19);
while(1)
{
IO0DIR = 1 << LED;
IO0CLR = 1 << LED;
Delay_us(100);
IO0SET = 1 << LED;
Delay_us(100);
}
return 0;
}
void Delay_ns(int n)
{
int i;
for (i=0;i<n;i++);
}
void init()
{
IO0DIR |= (ulong)1 << LCDRS;
IO0DIR |= (ulong)1 << LCDE;
IO0DIR |= (ulong)1 << LCDRW;
IO0DIR |= (ulong)1 << LCDCSL;
IO0DIR |= (ulong)1 << LCDCSR;
IO0DIR |= (ulong)1 << LED;
}
uchar getState()
{
IO0SET = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDRS;
IO0SET = 1 << LCDRW;
IO0CLR = 1 << LCDCSL;
IO0CLR = 1 << LCDCSR;
Delay_ns(5);
IO0SET = 1 << LCDE;
Delay_ns(10);
return IO1PIN;
}
int lcdBusy()
{
uchar state = 0;
state = getState();
if(state & (1 << 22))
{
return 1;
}
else
{
return 0;
}
}
void lcdCommand(uchar command)
{
IO1SET = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDCSL;
IO0CLR = 1 << LCDCSR;
IO0CLR = 1 << LCDRS;
IO0CLR = 1 << LCDRW;
Delay_ns(5);
IO0SET = 1 << LCDE;
Delay_ns(10);
IO1PIN = (IO1PIN & 0xff00ffff) | (command << 16);
}
void lcdOpen()
{
while(lcdBusy());
lcdCommand(0x3f);
}
void lcdStartLine(uchar lin)
{
lin |= 0xc0;
while(lcdBusy());
lcdCommand(lin);
}
void lcdSetPage(uchar page)
{
page &= 0x7;
page |= 0xb8;
while(lcdBusy());
lcdCommand(page);
}
void lcdSetRow(uchar row)
{
row &= 0x3f;
row |= 0x40;
while(lcdBusy());
lcdCommand(row);
}
void lcdWrite(uchar dat,uchar cs)
{
while(lcdBusy());
IO1DIR = 0x00000000;
IO0SET = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDE;
Delay_ns(5);
if(cs == 1)
{
IO0CLR = 1 << LCDCSL;
IO0SET = 1 << LCDCSR;
}
else
{
IO0CLR = 1 << LCDCSR;
IO0SET = 1 << LCDCSL;
}
IO0SET = 1 << LCDRS;
IO0CLR = 1 << LCDRW;
Delay_ns(5);
IO0SET = 1 << LCDE;
Delay_ns(10);
IO1PIN = (IO1PIN & 0xFF00FFFF) | (dat << 16);
}
uchar lcdRead(uchar cs)
{
uchar dat;
while(lcdBusy());
IO1PIN = 0xffffffff;
IO0SET = 1 << LCDE;
Delay_ns(5);
IO0CLR = 1 << LCDE;
Delay_ns(5);
if(cs == 1)
{
IO0CLR = 1 << LCDCSL;
Delay_ns(5);
IO0SET = 1 << LCDCSR;
Delay_ns(5);
}
else
{
IO0CLR = 1 << LCDCSR;
Delay_ns(5);
IO0SET = 1 << LCDCSL;
Delay_ns(5);
}
IO0SET = 1 << LCDRS;
IO0SET = 1 << LCDRW;
Delay_ns(2);
IO0SET = 1 << LCDE;
Delay_ns(10);
dat = IO1PIN ;
return dat >> 16;
}
void pixel(uchar x, uchar y)
{
uchar page,dX,dY;
uchar cs = 2;
uchar dot = 0;
if(x >= 64)
{
x -= 64;
}
else
{
cs = 1;
}
dX = x;
page = y / 8;
dY = y % 8;
lcdSetPage(page);
lcdSetRow(dX);
dot = lcdRead(cs);
dot ^= (1 << dY);
lcdSetPage(page);
lcdSetRow(dX);
lcdWrite(dot,cs);
}
屏完全就没有反应 屏是好的 各位高手们 救救我吧 快疯掉了 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|