I am writing a code to count the number of times a person enters a room and display it using UART. For the purpose of counting I am using IR sensor, connected to pin 0.2. So whenever this pin is low increment the count value and display it using UART.
Following is my code:
#include <LPC213X.H>
#include<stdio.h>
#include<string.h>
int i;
int count = 0;
char cnt[50];
#define delay for(i=0;i<127500;i++);
#define IR (IO0PIN & (1<<2))
void UART0_init(void)
{
PINSEL0 = 0x00000005; /* Enable UART0 Rx0 and Tx0 pins of UART0 */
U0LCR = 0x83; /* DLAB = 1, 1 stop bit, 8-bit character length */
//U0DLM = 0x00; /* For baud rate of 9600 with Pclk = 15MHz */
//U0DLL = 0x61; /* We get these values of U0DLL and U0DLM from formula */
U0LCR = 0x03; /* DLAB = 0 */
IODIR0 = 0x01;
}
void UART0_TxChar(char ch) /*A function to send a byte on UART0 */
{
while( !(U0LSR & 0x20));
U0THR = ch;
//while( (U0LSR & 0x40) == 0 );
/* Wait till THRE bit becomes 1 which tells that transmission is completed */
}
void displayCount(char cnt[]){
int len = strlen(cnt);
for(i=0;i<len;i++){
UART0_TxChar(cnt[i]);
}
}
int main(){
UART0_init();
count=0;
while(1){
if(IR == 0){
count++;
sprintf(cnt,"%d ",count);
displayCount(cnt);
delay;
delay;
}
}
return 0;
}
This works fine on keil and debug works as well, but when i dump the hex file of this code this doesn't work on proteus, i am confident that the proteus connection is proper.
But there is no output on the proteus virtual terminal.
Snaps:
Anyway to solve this problem?
User contributions licensed under CC BY-SA 3.0