Hi
so lately I have purchased an MSP430 board for a school project which soil moisture monitoring system. I did a little search on google to find a way of configuring the ports for both LCD and soil moisture but I end up with nothing.
however, I found this guy here on youtube, he provided the code, but I really need someone to provide me port configuration and diagram, I need to do this project asap before the deadline.
this is the code : [For clarity, TI moved the source code to an attachment]
#include <msp430.h> #include "MSP430_LCD.h" void readMoisture(); int main(void) { WDTCTL = WDTPW + WDTHOLD; P2DIR &= ~BIT1; P2IFG &= ~BIT1; P2IE |= BIT1; P2IES |= BIT1; P2DIR |= BIT2; P2OUT |= BIT2; ADC10CTL0 = ADC10SHT_2 + ADC10ON; ADC10CTL1 = INCH_7; ADC10AE0 |= 0x80; P1DIR |= 0x3F; initLCD(); clearLCD(); for (;;) { ADC10CTL0 |= ENC + ADC10SC; gotoxy(1,1); sendString(" MOISTURE VALUE"); gotoxy(1,2); sendString(" PERCENT"); readMoisture(); if( ( P2IN & BIT0 ) == 0 ){ P2OUT &= ~BIT2; _bis_SR_register( LPM4_bits | GIE ); } _delay_cycles(500000); } } void readMoisture(){ if (ADC10MEM <= 0x01B8) { gotoxy(2,2); sendString(" 100"); } else if (0x01B9 <=ADC10MEM && ADC10MEM <= 0x01D7) { gotoxy(2,2); sendString(" 90") ; } else if (0x01D8 <=ADC10MEM && ADC10MEM <= 0x01F6) { gotoxy(2,2); sendString(" 85") ; } else if (0x01F7 <=ADC10MEM && ADC10MEM <= 0x0215) { gotoxy(2,2); sendString(" 80") ; } else if (0x0216 <=ADC10MEM && ADC10MEM <= 0x0234) { gotoxy(2,2); sendString(" 75") ; } else if (0x0235 <=ADC10MEM && ADC10MEM <= 0x0253) { gotoxy(2,2); sendString(" 70") ; } else if (0x0254 <=ADC10MEM && ADC10MEM <= 0x0272) { gotoxy(2,2); sendString(" 65") ; } else if (0x0273 <=ADC10MEM && ADC10MEM <= 0x0291) { gotoxy(2,2); sendString(" 60") ; } else if (0x0292 <=ADC10MEM && ADC10MEM <= 0x02B0) { gotoxy(2,2); sendString(" 55") ; } else if (0x02B1 <=ADC10MEM && ADC10MEM <= 0x02CF) { gotoxy(2,2); sendString(" 50") ; } else if (0x02D0 <=ADC10MEM && ADC10MEM <= 0x02EE) { gotoxy(2,2); sendString(" 45") ; } else if (0x02EF <=ADC10MEM && ADC10MEM <= 0x030D) { gotoxy(2,2); sendString(" 40") ; } else if (0x030E <=ADC10MEM && ADC10MEM <= 0x032C) { gotoxy(2,2); sendString(" 35") ; } else if (0x032D <=ADC10MEM && ADC10MEM <= 0x034B) { gotoxy(2,2); sendString(" 30") ; } else if (0x034C <=ADC10MEM && ADC10MEM <= 0x036A) { gotoxy(2,2); sendString(" 25") ; } else if (0x036B <=ADC10MEM && ADC10MEM <= 0x0389) { gotoxy(2,2); sendString(" 20") ; } else if (0x038A <=ADC10MEM && ADC10MEM <= 0x03A8) { gotoxy(2,2); sendString(" 15") ; } else if (0x03A9 <=ADC10MEM && ADC10MEM <= 0x03C7) { gotoxy(2,2); sendString(" 10") ; } else if (0x03C8 <=ADC10MEM && ADC10MEM <= 0x03E6) { gotoxy(2,2); sendString(" 05") ; } else if (0x03E7 <= ADC10MEM) { gotoxy(2,2); sendString(" 00") ; } } #pragma vector = PORT2_VECTOR __interrupt void port2( void ){ _bic_SR_register_on_exit( LPM4_bits | GIE ); P2IFG &= ~BIT1; P2OUT |= BIT2; } //LCD Codes #include "MSP430.h" #include "MSP430_LCD.h" void resetLCD(){ P1OUT |= 0x0F; busyLCD(); P1OUT |= 0x03; enbLCD(); selectRegister(0); busyLCD(); P1OUT |= 0x03; selectRegister(0); enbLCD(); busyLCD(); P1OUT |= 0x03; selectRegister(0); enbLCD(); busyLCD(); P1OUT |= 0x02; selectRegister(0); enbLCD(); busyLCD(); } void initLCD(){ resetLCD(); sendCommand(0x28); sendCommand(0x0C); sendCommand(0x06); sendCommand(0x80); sendCommand(0x01); } void busyLCD(){ volatile unsigned int i; i=0; while(i<500) i++; } void enbLCD(){ P1OUT |= 0x20; P1OUT &= ~0x20; } void selectRegister(int i){ if(i==1) P1OUT |= 0x10; else P1OUT &= ~0x10; } void gotoxy(int x, int y){ if(y==1) sendCommand(0x80+(x-1)); else sendCommand(0xC0+(x-1)); } void clearLCD(){ sendCommand(0x01); } void sendCommand(unsigned char cmd){ P1OUT = 0x00; P1OUT |= ((cmd >> 4) & 0x0F); selectRegister(0); enbLCD(); P1OUT = 0x00; P1OUT |= (cmd & 0x0F); selectRegister(0); enbLCD(); busyLCD(); busyLCD(); } void sendData(unsigned char data){ P1OUT = 0x00; P1OUT |= ((data >> 4) & 0X0F); selectRegister(1); enbLCD(); P1OUT = 0x00; P1OUT |= (data & 0x0F); selectRegister(1); enbLCD(); } void sendString(char* str){ while(*str) sendData(*str++); } // LCD Header Files void initLCD(); void busyLCD(); void resetLCD(); void enbLCD(); void sendCommand(unsigned char); void selectRegister(int); void sendData(unsigned char); void sendString(char*); void gotoxy(int, int); void clearLCD();
I will be thankful if you could provide me with port configuration alongside a brief explanation of the code