This is One of the Solutions

LCD Interfacing Using Msp430

| Comments

There is a pot connect to the ADC of msp430 Ao(pin p1.0). The values of ADC10MEM displayed using LCD.

The Vcc for pot is taken from msp430 launchpad.so maximum voltage is 3.6v.

The msp430 10 bit ADC operates in the range 0 to 3.6V. If the input voltage is 0V,

the ADC generates a 10 bit value:

0 0 0 0 0 0 0 0 0 0

which is numerically equal to 0.

When the input voltage is 3.6V, the ADC

generates a 10 bit pattern:

1 1 1 1 1 1 1 1 1 1

which is numerically equal to 1023.

These values are stored in ADC10MEM.

The Vcc for LCD is given using another power supply of 5v.Because LCD display needed 5v for its functioning.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <msp430.h>

#define LCM_DIR P1DIR
#define LCM_OUT P1OUT

#define LCM_PIN_RS BIT2 // P1.2
#define LCM_PIN_EN BIT1 // P1.1
#define LCM_PIN_D7 BIT7 // P1.7
#define LCM_PIN_D6 BIT6 // P1.6
#define LCM_PIN_D5 BIT5 // P1.5
#define LCM_PIN_D4 BIT4 // P1.4
#define LCM_PIN_MASK ((LCM_PIN_RS | LCM_PIN_EN | LCM_PIN_D7 | LCM_PIN_D6 | LCM_PIN_D5 | LCM_PIN_D4))

#define FALSE 0
#define TRUE 1

//msp430 adc

void adc_init()

{
  ADC10CTL0 = ADC10ON | ADC10SHT_2 | SREF_0;
  ADC10CTL1 = INCH_0 | SHS_0 | ADC10DIV_0 | ADC10SSEL_0 | CONSEQ_0 ;
  ADC10AE0 = BIT0;
  ADC10CTL0 |= ENC ;
}

void start_conversion()

{
  ADC10CTL0 |= ADC10SC;
}

unsigned int converting()
{
  return ADC10CTL1 & ADC10BUSY;
}

// MSP430 LCD Code
void PulseLcm()
{  
  // pull EN bit low 
  LCM_OUT &= ~LCM_PIN_EN;
  __delay_cycles(200);
  // pull EN bit high    
  LCM_OUT |= LCM_PIN_EN;
  __delay_cycles(200);
  // pull EN bit low again   
  LCM_OUT &= (~LCM_PIN_EN);
  __delay_cycles(200);
}

void SendByte(char ByteToSend, int IsData)
{
  // clear out all pins  
  LCM_OUT &= (~LCM_PIN_MASK);   
  LCM_OUT |= (ByteToSend & 0xF0);   

  if (IsData == TRUE)
  {
      LCM_OUT |= LCM_PIN_RS;
  }
  else
  {
      LCM_OUT &= ~LCM_PIN_RS;
  }

  PulseLcm();
  LCM_OUT &= (~LCM_PIN_MASK);
  LCM_OUT |= ((ByteToSend & 0x0F) << 4);    

  if (IsData == TRUE)
  {
      LCM_OUT |= LCM_PIN_RS;
  }
  else
  {
      LCM_OUT &= ~LCM_PIN_RS;
  }    

  PulseLcm();
}

void LcmSetCursorPosition(char Row, char Col)
{
  char address;
  // construct address from (Row, Col) pair  

  if (Row == 0)
  {
      address = 0;
  }
  else
  {
      address = 0x40;
  }

  address |= Col;
  SendByte(0x80 | address, FALSE);
}

void ClearLcmScreen()
{
  // Clear display, return home
  SendByte(0x01, FALSE);
  SendByte(0x02, FALSE);
}

void InitializeLcm(void)
{
  LCM_DIR |= LCM_PIN_MASK;
  LCM_OUT &= ~(LCM_PIN_MASK);   
  __delay_cycles(100000);    
  LCM_OUT &= ~LCM_PIN_RS;
  LCM_OUT &= ~LCM_PIN_EN;  
  LCM_OUT = 0x20;
  PulseLcm();   
  SendByte(0x28, FALSE);   
  SendByte(0x0E, FALSE);   
  SendByte(0x06, FALSE);
}

void PrintStr(char *Text)
{
  char *c;
  c = Text;

  while ((c != 0) && (*c != 0))
  {
      SendByte(*c, TRUE);
      c++;
  }
}

void main(void)
{
  adc_init();   
  int i,a;    
  char b[5]; 
  WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer 
  InitializeLcm();  

  while(1)
  {    

      start_conversion();   
      while(converting());    
      a = ADC10MEM;   
      itoa(a,b,10);//integer to ASCII   
      ClearLcmScreen(); 
      PrintStr(b);    
      for(i=0;i<5000;i++);
  }
}

Related posts

Comments