Hi all,this is the main program of my project to read time from server and show on lcd panel.can anyone help me on what command should i add to read the reading from ADC (i give a voltage by using potentialmeter) and display on lcd? #include <stdlib.h> /* For system(). */ #include <stdio.h> /* For printf(). */ #undef HTONS #include "cs8900a.h" #include "uip.h" #include "uip_arp.h" #include "webclient.h" #include "lcd.h" #include "lpc21xx.h" static const struct uip_eth_addr ethaddr = {{0x00,0x00,0xe2,0x58,0xb6,0x6b}}; #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) #ifndef NULL #define NULL (void *)0 #endif /* NULL */ static unsigned short start, current; #define RT_CLOCK_SECOND 2048 /*---------------------------------------------------------------------- -------------*/ /** * \internal * A real-time clock. * * This example main() function uses polling of a real-time clock in * order to know when the periodic processing should be * performed. This is implemented using this function - rt_ticks(). In * this example unix implementation, it simply calls the unix function * gettimeofday() which returns the current wall clock time. * * For a micro-controller, a simple way to implement this function is * by having a counter that is incremented by a timer interrupt and * read by this function. * * The macro RT_CLOCK_SECOND should be defined as the approximate * number of ticks that are elapsed during one second. */ extern unsigned short rt_ticks(void); u8_t setTMP; int update_time; char s[8], rev_data[8]; struct tTimestamp { u8_t h; u8_t mi; u8_t s; }; static void SysInit(void) { // set PLL multiplier & divisor. // values computed from config.h PLLCFG = (4-1)|(1<<5)|(0<<5); // enable PLL PLLCON = 1; PLLFEED = 0xAA; // Make it happen. These two updates PLLFEED = 0x55; // MUST occur in sequence. // wait for PLL lock while (!(PLLSTAT & (1<<10))) continue; // enable & connect PLL PLLCON = (1<<0)|(1<<1); PLLFEED = 0xAA; // Make it happen. These two updates PLLFEED = 0x55; // MUST occur in sequence. // setup & enable the MAM MAMCR = 0; MAMTIM = ((14745000*4) + 19999999) / 20000000; MAMCR = 2; // set the peripheral bus speed // value computed from config.h VPBDIV = (2 & 0x03); // set the peripheral bus clock speed // set the interrupt controller defaults #if defined(RAM_RUN) MEMMAP = (1<<1); // map interrupt vectors space into SRAM #elif defined(ROM_RUN) MEMMAP = (1<<0); // map interrupt vectors space into FLASH #else #error RUN_MODE not defined! #endif } void init_rtc(void) { int myPREINT=((((14745000*4)/2)/32768)-1); int myPREFRAC=(((14745000*4)/2)-((myPREINT+1)*32768)); ILR = 0x3; // Disable 32'768 interrupt PREINT = myPREINT; PREFRAC = myPREFRAC; set_time(); CCR = 0x11; /* disabale CTC-Reset and enable clock with CLKEN */ } void set_time(void) { int tmphrs[2], tmpmin[2], tmpsec[2]; CCR = 0x10; tmphrs[0] =(rev_data[0] & 0x0f); tmphrs[1] =(rev_data[1] & 0x0f); HOUR = (tmphrs[0]*10 + tmphrs[1]); // Hours tmpmin[0] =(rev_data[3] & 0x0f); tmpmin[1] =(rev_data[4] & 0x0f); MIN = (tmpmin[0]*10 + tmpmin[1]); // Minutes tmpsec[0] =(rev_data[6] & 0x0f); tmpsec[1] =(rev_data[7] & 0x0f); SEC = (tmpsec[0]*10 + tmpsec[1]); // Seconds CCR = 0x01; } void RTC_GetTime(struct tTimestamp *ts) { ts->s = (u8_t)SEC; ts->mi = (u8_t)MIN; ts->h = (u8_t)HOUR; } /*---------------------------------------------------------------------- -------------*/ int main(void) { struct tTimestamp ts; u8_t i, arptimer, num_display; setTMP=10; SysInit(); /* Initialize the uIP TCP/IP stack. */ uip_init(); uip_arp_init(); /* Register the Ethernet MAC address with uIP. In reality, the MAC address should be obtained from the EEPROM of the network hardware before calling this function. */ // uip_setethaddr(ethaddr); /* Setup the IP address and netmask. */ // uip_ipaddr(addr, 192,168,0,30); // uip_sethostaddr(addr); // uip_ipaddr(addr, 255,255,255,0); // uip_setnetmask(addr); /* Configure the IP address of the default router. */ // uip_ipaddr(addr, 192,168,0,1); // uip_setdraddr(addr); /* Initialize the device driver. */ cs8900a_init(); /* Initialize the HTTP client. */ webclient_init(setTMP); start = rt_ticks(); arptimer = 0; while(1) { update_time=0; num_display=100; /* Let the tapdev network device driver read an entire IP packet into the uip_buf. If it returns > 0, there is a packet in the uip_buf buffer. */ uip_len = cs8900a_poll(); if(uip_len > 0) { /* A packet is present in the packet buffer. We call the appropriate ARP functions depending on what kind of packet we have received. If the packet is an IP packet, we should call uip_input() as well. */ if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); cs8900a_send(); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { cs8900a_send(); } } } else { /* The poll function returned 0, so no packet was received. Instead we check if there is time that we do the periodic processing. */ current = rt_ticks(); if((u16_t)(current - start) >= (u16_t)RT_CLOCK_SECOND / 2) { start = current; for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); cs8900a_send(); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); cs8900a_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(++arptimer == 20) { uip_arp_timer(); arptimer = 0; } } } if (update_time == 1) { init_rtc(); lcd_init(); do { Display(); num_display--; }while(num_display); } if(num_display==0) {setTMP++; webclient_init(setTMP);} } return 0; } /*---------------------------------------------------------------------- -------------*/ /*void uip_log(char *m) { // printf("uIP log message: %s\n", m); }*/ /*---------------------------------------------------------------------- -------------*/ void resolv_found(char *name, u16_t *ipaddr) { u16_t *ipaddr2; if(ipaddr == NULL) { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("Host not found"); } else { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("Found name"); } } void webclient_closed(void) { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("closed"); } void webclient_aborted(void) { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("Connection aborted"); delay(); } void webclient_timedout(void) { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("time out"); } void webclient_connected(void) { lcd_init(); lcd_cursor_off(); lcd_cursor_home(); lcd_clear(); lcd_print("waiting"); delay(); } void webclient_datahandler(char *data, u16_t len) { rev_data[0] = *(data); rev_data[1] = *(data + 1); rev_data[2] = *(data + 2); rev_data[3] = *(data + 3); rev_data[4] = *(data + 4); rev_data[5] = *(data + 5); rev_data[6] = *(data + 6); rev_data[7] = *(data + 7); update_time = 1; } void Display(void) { struct tTimestamp ts; RTC_GetTime(&ts); s[0]=ts.h/10+'0'; s[1]=ts.h%10+'0'; s[2]=':'; s[3]=ts.mi/10+'0'; s[4]=ts.mi%10+'0'; s[5]=':'; s[6]=ts.s/10+'0'; s[7]=ts.s%10+'0'; delay(); delay(); lcd_cursor_off(); delay(); delay(); //lcd_clear(); //delay(); //delay(); lcd_cursor_home(); delay(); delay(); lcd_putchar(s[0]); delay(); lcd_putchar(s[1]); delay(); lcd_putchar(s[2]); delay(); lcd_putchar(s[3]); delay(); lcd_putchar(s[4]); delay(); lcd_putchar(s[5]); delay(); lcd_putchar(s[6]); delay(); lcd_putchar(s[7]); delay(); delay(); }
Which processor are you using? Try looking in the WinArm examples folder. There is an lpc2129 example that uses the ADCs. If you are using a SAM7 series processor, check the Atmel site for example code.
Jim Kaz wrote: > Which processor are you using? > > Try looking in the WinArm examples folder. There is an lpc2129 example > that uses the ADCs. If you are using a SAM7 series processor, check the > Atmel site for example code. Hi Jim Kaz, i am using Olimex LPC-E2129.I had download the the examples from WinARM examples folder.But i dun know how to integrate the code in my main program.can you help me on that?i wan to display the value from adc at the lcd panel.(I supply a voltage to P0.27 by using potentiometer).hope to hear from u soon...Thanks.
Tiong Loh wrote: > Hi Jim Kaz, > i am using Olimex LPC-E2129.I had download the the examples from WinARM > examples folder.But i dun know how to integrate the code in my main > program.can you help me on that?i wan to display the value from adc at > the lcd panel.(I supply a voltage to P0.27 by using potentiometer).hope > to hear from u soon...Thanks. I'm pretty busy with a bunch of work stuff right now, so I may be able to help you, but its not going to be in a timely manner. You're best off trying to figure it out for yourself. I've also never looked at code for the LPC, so I'm not sure how long it would take me to get up to speed on what all the different registers do and how they interact, and I probably don't have that time available.
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.