Token Display:
Code:
#include<lpc214x.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
int main()
{
IO0DIR=IO0DIR|(0x7f<<16);
pllinit();
lcdinit();
//PINSEL0=PINSEL0|0x20
IO0DIR=IO0DIR|(0xff<<19);
PINSEL0=PINSEL0|(2<<4);//select CAP0.0
T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
lcdstring("wainting for pulse or event");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}
void lcdstring(char *p)
{
lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
lcdcmd(0x1c);
p++;
}
}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);
lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);
lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}
void convert(unsigned long int a) //say a=678
{
int i;int a1;
char pos=0xcd;
for(i=0;i<=9;i++)
{
lcdcmd(pos);
a1=a%10; //a1=8//7//6//0
a=a/10; //a=67//6//0//0
lcdstring("EVENT NO:");
lcddata(0x30+a1);
pos--;
}
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
PLL0CFG=0x24;
PLL0CON=PLL0CON|(1<<PLLE);
PLL0FEED=0xAA;
PLL0FEED=0x55;
//PLL0CON=PLL0CON|(1<<PLLC);
while( (PLL0STAT & (1<<PLOCK))==0);
PLL0CON=PLL0CON|3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x01;
}
*/
#include<lpc214x.h>
#include<stdio.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
char result[4];
int main()
{
IO0DIR=IO0DIR|(0x7f<<16);
IO0DIR=IO0DIR|(0xff<<19);
PINSEL0=PINSEL0|(2<<4);//select CAP0.0
pllinit();
lcdinit();
lcdcmd(0x80);
lcdstring("EVENT COUNTING");
delay(200);
lcdcmd(1);
lcdstring("EVENT NO:");
delay(200);
sprintf(result,"%d",T0TC);
lcdcmd(0x8A);
lcdstring(result);
//PINSEL0=PINSEL0|0x20
T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
//lcdstring("wainting for pulse or event");
//lcdcmd(0x80);
//lcdstring("EVENT NO:");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}
void lcdstring(char *p)
{
//lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
//lcdcmd(0x1c);
p++;
}
}
void convert(unsigned long int a) //say a=678
{
sprintf(result,"%d",a);
lcdcmd(0x80);
lcdstring("EVENT NO:");
lcdstring(result);
delay(2000);
return;
}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);
lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);
lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
PLL0CFG=0x24;
PLL0CON=PLL0CON|(1<<PLLE);
PLL0FEED=0xAA;
PLL0FEED=0x55;
//PLL0CON=PLL0CON|(1<<PLLC);
while( (PLL0STAT & (1<<PLOCK))==0);
PLL0CON=PLL0CON|3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x01;
}