Write Measured Voltage on LCD Screen (MSP430 Applications in C ++)
This tutorial shows us how to measure voltage with using MSP430, and display the voltage value into the LCD screen.
Codes are half turkish so if you guys have question or misunderstoods you can mail me. I can glady help you !
mail: g.haddeler@gmail.com
Have fun !!
First you need to create an LCD library. Add a tab outside the main tab and get these codes.
Lib Codes :
-------------------------------
#include "io430.h"
#include "lcd_msp.h"
#define E_1 0x08
#define RS_E_1 0x0C
void delay(unsigned long int d)
{
d*=100;
for(;d>0;d--);
}
void hc595_yaz(unsigned char gelen)
{
for(char i=8;i>0;i--)
{
Data=0;
if(gelen & 0x80)
Data=1;
Clock=1;
Clock=0;
gelen*=2;
}
Storage=1;
Storage=0;
}
void lcd_write(unsigned char port)
{
//ilk 4 bit gönderiliyor...
hc595_yaz(E_1);
hc595_yaz(( port & 0xF0) | E_1);
hc595_yaz(((port & 0xF0) | E_1) & 0xF0);
//Son 4 bit gönderiliyor...
hc595_yaz(E_1);
hc595_yaz(( port<<4 ) | E_1);
hc595_yaz(((port<<4 ) | E_1) & 0xF0);
}
void lcd_putch(unsigned char port)
{
//ilk 4 bit gönderiliyor...
hc595_yaz(RS_E_1);
hc595_yaz(( port & 0xF0 ) | RS_E_1);
hc595_yaz(((port & 0xF0 ) | RS_E_1) & 0xF4);
//Son 4 bit gönderiliyor...
hc595_yaz(RS_E_1);
hc595_yaz(( port<<4) | RS_E_1);
hc595_yaz(((port<<4) | RS_E_1) & 0xF4);
}
void lcd_puts(const char * s)
{
nop();
while(*s)
lcd_putch(*s++);
}
void lcd_temizle(void)
{
lcd_write(0x1);
delay(2);
}
void lcd_goto(char x, char y)
{
if(x==1)
lcd_write(0x80+((y-1)%16));
else
lcd_write(0xC0+((y-1)%16));
}
void lcd_init(void)
{
hc595_yaz(0x00);
delay(15);
hc595_yaz(0x08);
lcd_write(0x02); // Cursor is at 0x0
delay(2);
lcd_write(0x28); // 4 Bit , Double Line LCD
lcd_write(0x0C); // Cursor is hiding
lcd_temizle(); // Screen is cleaned
lcd_write(0x06); // Writing to the right is active.
lcd_write(0x80); // LCD is in the First Row Position
}
--------------------------------------------------------
Put these bottom codes in the Main Tab:
#include "io430.h"
#include "in430.h"
#include "lcd_msp.h"
void integer_yaz(unsigned int,char);
void deger_goster(unsigned int);
void a5_init(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ + DIVA_3;
P1DIR |= BIT0 + BIT1 + BIT2;
a5_init();
lcd_init();
delay(2000);
while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
deger_goster(ADC10MEM);
}
}
// ADC10 Interrrupt Vector
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF);
}
void deger_goster(unsigned int ham)
{
unsigned int volt=0;
volt=(float)(ham/2.87);
lcd_goto(1,1);
lcd_puts("10 Bit = ");
integer_yaz(ADC10MEM,0);
lcd_goto(2,1);
lcd_puts("Gerilim = "); // Voltage =
integer_yaz(volt,1);
}
void a5_init()
{
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_5 + ADC10SSEL_1 + ADC10DIV_5;
ADC10AE0 = BIT5;
}
void integer_yaz(unsigned int deger,char flag)
{
lcd_putch( deger/1000+48);
lcd_putch((deger%1000)/100+48);
if(flag==1) lcd_putch('.');
lcd_putch((deger%100)/10+48);
lcd_putch((deger)%10+48);
}
Yorumlar
Yorum Gönder