#include <LPC21xx.H>
unsigned char card_id[12];
void delay(unsigned long b){
while (--b!=0);
}
void init_serial(void)
{
PINSEL0 = 0x00050005; /* Enabling RxD0 and TxD0, RxD1 and TxD1 */
U0LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit * for UART0*/
U0DLL = 0XC3;
U0FCR = 0x81; /*Enable the FIFO registers*/
U0DLM = 0X00;
U0LCR = 0x00000003; /* DLAB = 0 for UART0*/
U1LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit for UART1*/
U1DLL = 0XC3;
U1LCR = 0x00000003; /* DLAB = 0 * for UART1*/
U1FCR = 0x81; /*Enable the FIFO registers*/
}
int receive(void) /*function for receiving data from sensor (reads byte by byte & returns value if exist) */
{
unsigned char k;
//while (!(U1LSR & 0x01))
//if(U1RBR==0x0a)
for(k=0;k<=11;k++)
{
while (!(U1LSR & 0x01)); /* If U0LSR 1st bit contains valid data, then return value of U1RBR*/
card_id[k] =U1RBR;
U1LSR = U1LSR & 0x00;
}
return (0);
}
void write_command(int cmd) {
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1CLR |= 0X00020000; /* Register Select = 0,Command */
IO1SET |= 0x00f00000 & cmd; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
delay(30000);
IO1CLR |= 0x00080000; /* set E to low */
}
void write_data(int dat) {
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1SET |= 0X00020000; /* Register Select = 1,Data */
IO1SET |= 0x00f00000 & dat; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
delay(30000); //delay ~2ms
IO1CLR |= 0x00080000; /* Set E to low */
}
void lcd_data(char dat){
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd){
write_command(cmd << 16);
write_command(cmd << 20);
}
void printlcd(unsigned char *CPtr){
while(*CPtr != '\0') {
lcd_data(*CPtr);
CPtr++;
delay(20000);
}
}
void init_lcd(void) {
IO1DIR |= 0x00FE0000;
delay(200000) ;
write_command(0x30 << 16);
delay(100000);
write_command(0x30 << 16);
delay(100000);
write_command(0x30 << 16);
delay(100000);
write_command(0x20 << 16);
lcd_command(0x01); /* clear display */
lcd_command(0x06); /* auto address inc */
lcd_command(0x0c); /* cursor off */
lcd_command(0x80); /* first location */
}
main(void)
{
unsigned int i;
init_lcd();
init_serial();
while(1)
{
receive();
for(i=0;i<=11;i++)
{
printlcd(card_id);
delay(20);
}
}
}
http://www.pantechsolutions.net/microcontroller-boards/uart-interfacing-with-lpc2148-arm7-primer
unsigned char k; // declared as global
int receive(void) /*function for receiving data from sensor (reads byte by byte & returns value if exist) */
{
if(!(U1LSR & 0x01)) // valid data indication
{
card_id[k++] =U1RBR;
U1LSR = U1LSR & 0x00;
}
return (0);
}
}
http://embedranics.blogspot.com/2012/01/interrupt-example-programs-for-timer-01.html
The problem is solved now.
#include <LPC21xx.H>
unsigned char card_id[11];
unsigned char card_id2[11];//= {'1','2','3','4','5','6','7','8','9','0','1'};
void delay(unsigned long b){
while (--b!=0);
}
void init_serial(void)
{
PINSEL0 = 0x00050005; /* Enabling RxD0 and TxD0, RxD1 and TxD1 */
U0LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit * for UART0*/
VPBDIV = 0x2;
U0DLL = 0Xc3; //Baud rate 9600
U0FCR = 0x81; /*Enable the FIFO registers*/
U0DLM = 0X00;
U0LCR = 0x00000003; /* DLAB = 0 for UART0*/
U1LCR = 0x00000083; /* 8 bits, no Parity, 1 Stop bit for UART1*/
U1DLL = 0Xc3;
U1LCR = 0x00000003; /* DLAB = 0 * for UART1*/
U1FCR = 0x81; /*Enable the FIFO registers*/
}
int receive(void) /*function for receiving data from sensor (reads byte by byte & returns value if exist) */
{
unsigned char k,j;
while (!(U1LSR & 0x01) && (U1RBR != 0x81));
for(k=0;k<=11;k++)
{
while (!(U1LSR & 0x01)); /* If U0LSR 1st bit contains valid data, then return value of U1RBR*/
card_id[k] =U1RBR;
//U1LSR = U1LSR & 0x00;
}
for(j=0;j<=11;j++);
{
card_id2[k] = card_id [k+ 0x48];
}
return (0);
}
void write_command(int cmd) {
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1CLR |= 0X00020000; /* Register Select = 0,Command */
IO1SET |= 0x00f00000 & cmd; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
delay(30000);
IO1CLR |= 0x00080000; /* set E to low */
}
void write_data(int dat) {
IO1CLR |= 0x00f00000; /* Clear D4-D7 */
IO1CLR |= 0x00040000; /* Read/Write = 0 */
IO1SET |= 0X00020000; /* Register Select = 1,Data */
IO1SET |= 0x00f00000 & dat; /* Set D4-D7 */
IO1SET |= 0X00080000; /* Enable = 1 */
delay(30000); //delay ~2ms
IO1CLR |= 0x00080000; /* Set E to low */
}
void lcd_data(char dat){
write_data(dat << 16);
write_data(dat << 20);
}
void lcd_command(char cmd){
write_command(cmd << 16);
write_command(cmd << 20);
}
void printlcd(unsigned char *CPtr){
while(*CPtr != '\0') {
lcd_data(*CPtr);
CPtr++;
delay(20000);
}
}
void init_lcd(void)
{
IO1DIR |= 0x00FE0000;
delay(200000) ;
write_command(0x30 << 16);
delay(100000);
write_command(0x30 << 16);
delay(100000);
write_command(0x30 << 16);
delay(100000);
write_command(0x20 << 16);
lcd_command(0x01); /* clear display */
lcd_command(0x06); /* auto address inc */
lcd_command(0x0c); /* cursor off */
lcd_command(0x80); /* first location */
}
int main(void)
{
unsigned int i,k=0;
init_lcd();
init_serial();
printlcd("A");
while(1)
{
receive();
for(i=0;i<=11;i++)
{
lcd_command(0x80);
printlcd(card_id);
}
for(k=0;k<11;k++)
{
card_id[k]= '\0';
}
/*for(k=0;k<11;k++)
{
card_id[k]= card_id2[k];
}*/
/*for(k=0;k<11;k++)
{
lcd_command(0x80);
printlcd(card_id2);
}*/
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?