IR ARM CODE
/* * Project name: IR sensor * Copyright (c) Researchdesignlab.com * Description: * Test configuration: MCU: LPC2129 Dev.Board: LPC2129 mini Oscillator: 12 MHz Software: Keil uVision3 */ #include<stdio.h> #include"lpc21xx.h" // header file #include<string.h> //******************************************************************* void SEND_CMD_2_LCD(unsigned char); // function protoype void SEND_2_LCD(unsigned char *, unsigned char); void DISPLAY_ON_LCD(unsigned char DATA); #define sw4 0x00010000 void DELAY(void); void LCD_DELAY(void); unsigned int LCD_RS=0X01000000; // pin declerations unsigned int LCD_EN=0X02000000; unsigned int LCD_DATA_LINES=0X00003C00; unsigned char da,da1,da2; //******************************************************************* int main() { unsigned char LCD_CMD[]={0X20,0X28,0X0f,0X06,0X01,0X80},COUNT; // LCD commands IODIR0|=LCD_DATA_LINES; IODIR1=0X03300000; for(COUNT=0;COUNT<6;COUNT++) SEND_CMD_2_LCD(LCD_CMD[COUNT]); // LCD INIT function call DELAY(); DELAY(); while(1) { if((IOPIN1&sw4)==sw4) // IR IS HIGH enter the loop { SEND_CMD_2_LCD(0x01); // clear the display SEND_2_LCD("IR HIGH",0x80); // display on ist lne DELAY(); } else // IR IS low enter the loop { SEND_CMD_2_LCD(0x01); // clear the display SEND_2_LCD("IR LOW",0x80); // display on ist lne DELAY(); } } } void DELAY(void) { unsigned int X=800000; while(X--); } void LCD_DELAY(void) { unsigned int X=20000; // delay calculation subroutine while(X--); } void SEND_CMD_2_LCD(unsigned char DATA) { unsigned int TEMP; // LCD command write function IOCLR0=LCD_DATA_LINES; TEMP=DATA; TEMP=((TEMP&0xf0)<<6); IOCLR1=LCD_RS; IOSET0=TEMP; IOSET1=LCD_EN; LCD_DELAY(); LCD_DELAY(); IOCLR1=LCD_EN; IOCLR0=LCD_DATA_LINES; LCD_DELAY(); TEMP=DATA; TEMP=((TEMP&0x0f)<<10); IOCLR1=LCD_RS; IOSET0=TEMP; IOSET1=LCD_EN; LCD_DELAY(); LCD_DELAY(); IOCLR1=LCD_EN; IOCLR0=LCD_DATA_LINES; } void DISPLAY_ON_LCD(unsigned char DATA) { unsigned int TEMP; IOCLR0=LCD_DATA_LINES; TEMP=DATA; //LCD data write function TEMP=((TEMP&0xf0)<<6); IOSET1=LCD_RS; IOSET0=TEMP; IOSET1=LCD_EN; LCD_DELAY(); LCD_DELAY(); IOCLR1=LCD_EN; IOCLR0=LCD_DATA_LINES; LCD_DELAY(); TEMP=DATA; TEMP=((TEMP&0x0f)<<10); IOSET1=LCD_RS; IOSET0=TEMP; IOSET1=LCD_EN; LCD_DELAY(); LCD_DELAY(); IOCLR1=LCD_EN; IOCLR0=LCD_DATA_LINES; } void SEND_2_LCD(unsigned char *PTR, unsigned char POS) { SEND_CMD_2_LCD(POS); while(*PTR) { // sending the data to LCD data line function DISPLAY_ON_LCD(*PTR); PTR++; } LCD_DELAY(); LCD_DELAY(); }