0% found this document useful (0 votes)
84 views2 pages

Test Ads7841.c

This document contains C code to display analog channel values from an ADC on an LCD screen. It includes functions to convert long integers to ASCII strings, initialize the LCD, and display the continuously updating analog readings from 4 channels in two rows on the LCD screen. The main program loop reads the analog values, converts them to strings, clears the display and writes the new values to the LCD after a short delay.

Uploaded by

Sandeep Kashyap
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views2 pages

Test Ads7841.c

This document contains C code to display analog channel values from an ADC on an LCD screen. It includes functions to convert long integers to ASCII strings, initialize the LCD, and display the continuously updating analog readings from 4 channels in two rows on the LCD screen. The main program loop reads the analog values, converts them to strings, clears the display and writes the new values to the LCD after a short delay.

Uploaded by

Sandeep Kashyap
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <p89v51rd2.h> #include "../lcd/lcd.h" #include "ads7841.

h" #define NUMBER_OF_DIGITS 16 /*************** Convert long integer to ascii ************/ void _ultoa_(unsigned long value, char* string, unsigned char radix) { unsigned char index; // Counter of digit char buffer[NUMBER_OF_DIGITS]; // Data buffer index = NUMBER_OF_DIGITS; // Load counter by digit count do { buffer[--index] = '0' + (value % radix); // Convert confi guration by radix(10 or 16) if ( buffer[index] > '9') buffer[index] += 'A' - '9' - 1; // For base over 10(base 16) value /= radix; // Div by to calculate into next digit } while (value != 0); // End for convert? do { *string++ = buffer[index++]; buffer } while ( index < NUMBER_OF_DIGITS ); *string = 0; } /*************** Convert long integer to ascii ************/ void _ltoa_(long value_l, char * string_l, unsigned char radix_l) { if (value_l < 0 && radix_l == 10) // For value < 0 (base 10) { *string_l++ = '-'; // Load sign '-' for display _ultoa_(-value_l, string_l, radix_l); // Convert long integer } else { _ultoa_(value_l, string_l, radix_l); // Convert long integer } } void PowerOn() { unsigned char inner, outer; for (outer = 0x00; outer < 0x10; outer++) { for (inner = 0x00; inner < 0xFF; inner++); } LCD_init(); for (inner = 0; inner < 10; inner++) LCD_delay(2); } // Over of digit count? // Place null for end string // Load convert value to string

/***************************** Main Program **********************************/ void main() { unsigned char i,j; char buff[4]; PowerOn(); LCD_row1(); LCD_puts("Ch0:"); LCD_command(0x88); LCD_puts("Ch1:"); LCD_row2(); LCD_puts("Ch2:"); LCD_command(0xC8); LCD_puts("Ch3:"); while(1) { LCD_command(0x84); LCD_puts(" "); hannel 0 value */ _ltoa_(analog(0), buff, 10); LCD_command(0x84); LCD_puts(buff); LCD_command(0x8C); LCD_puts(" "); analog channel 1 value */ _ltoa_(analog(1), buff, 10); LCD_command(0x8C); LCD_puts(buff); LCD_command(0xC4); LCD_puts(" "); analog channel 2 value */ _ltoa_(analog(2), buff, 10); LCD_command(0xC4); LCD_puts(buff); LCD_command(0xCC); LCD_puts(" "); analog channel 3 value */ _ltoa_(analog(3), buff, 10); LCD_command(0xCC); LCD_puts(buff); for (i=0; i<0xFF ;i++ ) for (j=0; j<0xFF; j++); } } /* Show analog c

/* Show previous

/* Show previous

/* Show previous

/* Delay for a while */

You might also like