#include “LPC17xx.h” #define rs 0x2 #define en 0x1 unsigned int read_adc(void){ unsigned int i; LPC_ADC -> ADCR |= 0x01000000; do{ i = LPC_ADC -> ADDR0; } while (( i & 0x80000000 ) == 0); return ( i >> 4) & 0x03ff; }
void delay (unsigned int i){ while ( i --); } Void command ( unsigned char i){ LPC_GPIO1 -> FIOCLR |= 0xffffff00; LPC_GPIO1 -> FIOSET | = ( i << 20); LPC_GPIO1 -> FIOCLR = rs; LPC_GPIO1 -> FIOSET = en; delay ( 100000); LPC_GPIO1 -> FIOCLR = en; }
Void command ( unsigned char i){ LPC_GPIO1 -> FIOCLR | = 0xffffff00; LPC_GPIO1 -> FIOSET | = ( i << 20); LPC_GPIO1 -> FIOSET = rs; LPC_GPIO1 -> FIOSET = en; delay ( 100000); LPC_GPIO1 -> FIOCLR = en; } main (void){
unsigned int value , value_1, value_10; LPC_SC -> PCONP = | ( 1 << 12); LPC_PINCON -> PINSEL1 | = (1 << 14);
LPC_ADC -> ADCR = 0x00200301; LPC_GPIO0 ->FIODIR | = 0x000000ff; LPC_GPIO1 ->FIODIR | = 0x00000003; command(0x38); delay(100000); command (0x0e); delay(100000); command(0x01); delay(100000); command(0x80);
delay( 100000); data( ‘T’); delay(100000); data(‘:’); delay(100000); while(1) { value = read_adc(); value = value /12; value_10 = value /10; value_1 = value – ( value_10 * 10); command(0x82); delay(100000); data(value_10); delay(100000); data(value_1); delay(100000); }}