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

CVBN

Uploaded by

d4rkfantasyy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views2 pages

CVBN

Uploaded by

d4rkfantasyy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <msp430.

h> LCD_OUT = ((LCD_OUT & 0x0F) | ((value << 4) & 0xF0));


// Write low nibble next
#include <inttypes.h>
pulseEN();
#include<stdio.h>
delay(1);}
#define CMD 0
/***@brief Function to print a string on LCD
#define DATA 1
*@param *s pointer to the character to be written.
#define AIN BIT0 // Channel A0
*@return void**/
#define LCD_OUT P1OUT
void lcd_print(char *s)
#define LCD_DIR P1DIR
{while(*s)
#define D4 BIT4
{lcd_write(*s, DATA);
#define D5 BIT5
s++;}}
#define D6 BIT6
/***@brief Function to move cursor to desired position on LCD
#define D7 BIT7
*@param row Row Cursor of the LCD
#define RS BIT2
*@param col Column Cursor of the LCD
#define EN BIT3
*@return void**/
/***@brief Delay function for producing delay in 0.1 ms
increments void lcd_setCursor(uint8_t row, uint8_t col)

*@param t milliseconds to be delayed {const uint8_t row_offsets[] = { 0x00, 0x40};

*@return void**/ lcd_write(0x80 | (col + row_offsets[row]), CMD);

void delay(uint16_t t) delay(1);}

{uint16_t i; /** *@brief Function to change numeric value into it's


corresponding char array
for(i=t; i > 0; i--)
*@param num Number which has to be displayed
__delay_cycles(100);}
*@return void **/
/***@brief Function to pulse EN pin after data is written
void lcd_printNumber(unsigned int num)
*@return void**/
{char buf[3]; // Creating a array of size 3
void pulseEN(void)
char *str = &buf[2]; // Initializing pointer to end of the
{LCD_OUT |= EN; array\

delay(1); *str = '\0'; // storing null pointer at end of string

LCD_OUT &= ~EN; do

delay(1);} {unsigned long m = num; // Storing number in variable m

/***@brief Function to write data/command to LCD num /= 10; // Dividing number by 10

*@param value Value to be written to LED char c = (m - 10 * num) + '0'; // Finding least place value and
adding it to get character value of digit
*@param mode Mode -> Command or Data
*--str = c; // Decrementing pointer value and
*@return void**/ storing character at that character

void lcd_write(uint8_t value, uint8_t mode) } while(num);

{if(mode == CMD) lcd_print(str);

LCD_OUT &= ~RS; // Set RS -> LOW for Command /***@brief Initialize LCD **/
mode
void lcd_init()
else
{LCD_DIR |= (D4+D5+D6+D7+RS+EN);
LCD_OUT |= RS; // Set RS -> HIGH for Data mode
LCD_OUT &= ~(D4+D5+D6+D7+RS+EN);
LCD_OUT = ((LCD_OUT & 0x0F) | (value & 0xF0)); //
Write high nibble first delay(150); // Wait for power up ( 15ms )

pulseEN(); lcd_write(0x33, CMD); // Initialization Sequence 1

delay(1); delay(50); // Wait ( 4.1 ms )


lcd_write(0x32, CMD); // Initialization Sequence 2 lcd_setCursor(1,3);

delay(1); // Wait ( 100 us ) lcd_printNumber(int_part); // Displaying integer part


of ADC value
// All subsequent commands take 40 us to execute, except clear
& cursor return (1.64 ms) lcd_print(".");

lcd_write(0x28, CMD); // 4 bit mode, 2 line lcd_printNumber(decimal_part); // Displaying decimal


part of ADC value
delay(1);
lcd_setCursor(1,7);
lcd_write(0x0C, CMD); // Display ON, Cursor OFF, Blink
OFF lcd_print("V");

delay(1); delay(6000);

lcd_write(0x01, CMD); // Clear screen }

delay(20); }

lcd_write(0x06, CMD); // Auto Increment Cursor

delay(1);

lcd_setCursor(0,0); // Goto Row 1 Column 1}

/** * @brief

* These settings are wrt enabling ADC10 on Lunchbox**/

void register_settings_for_ADC10()

{ADC10AE0 |= AIN; // P1.0 ADC option select

ADC10CTL1 = INCH_0; // ADC Channel -> 1


(P1.0)

ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON; // Ref ->


Vcc, 64 CLK S&H , ADC - ON}

/*@brief entry point for the code*/

void main(void)

{WDTCTL = WDTPW + WDTHOLD; //! Stop


Watchdog (Not recommended for code in production and devices
working in field)

lcd_init(); // Initializing LCD

register_settings_for_ADC10();

while(1)

ADC10CTL0 |= ENC + ADC10SC; // Sampling and


conversion start

while(ADC10CTL1 & ADC10BUSY); // Wait for


conversion to end

float adc_value = 0;

adc_value = (ADC10MEM) * (3.30) / (1023.00); // mapping


10-bit conversion result of ADC to corresponding voltage

int int_part = adc_value; // Integer part of


calculated ADC value

int decimal_part = (adc_value - (float)int_part) * 10.0 ; //


Decimal part of calculated ADC value

lcd_write(0x01, CMD); // Clear screen

delay(20);

lcd_setCursor(0,0);

lcd_print("Pot Reading");

You might also like