Electrical Engineering Asked by Jan Franco on January 4, 2022
I am new at this. I am trying to interfacing 1602A LCD display with MSP430G2553 via PCF8574. When I run the code, nothing happens:
#include <msp430.h>
unsigned int *ptxData;
unsigned int count = 0;
// [0..3] -> power on, [4..5] -> function set, [6..7] -> display off, cursor off, blink off
// [8..9] -> clear screen, [10..11] -> right, do not shift, [12..13] -> display on, cursor on
// [14..15] -> write char 'B'
unsigned int txData[] = {0x03, 0x03, 0x03, 0x02, 0x02, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x06, 0x00, 0x0F, 0x24, 0x22};
void main() {
WDTCTL = WDTPW | WDTHOLD;
// for i2c pins
P1SEL = 0xC0;
P1SEL2 = 0xC0;
// i2c config
UCB0CTL1 |= UCSWRST;
UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC;
UCB0CTL1 = UCSSEL_3;
UCB0BR0 = 12;
UCB0BR1 = 0;
UCB0I2CSA = 0x27; // slave address
UCB0CTL1 &= ~UCSWRST;
// enable tx interrupt
IE2 |= UCB0TXIE;
_enable_interrupts();
// start to transmit data
ptxData = txData;
UCB0CTL1 |= UCTR + UCTXSTT;
while (1);
}
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void){
// send txData elements one by one
UCB0TXBUF = *ptxData;
count++;
*ptxData++;
// if txData ends, start from beginning
if (count == 16) {
count = 0;
ptxData -= 16;
}
}
What am I missing, can you help me?
The code is obviously missing comments what it does. If it did have comments what it does or what it is supposed to do, it would be more clear to find out what's wrong.
First of all the transmit data pointer is initialized to null, so it is sending garbage data instead of data from the transmit data array.
Second problem is that the array contains only command nybbles that must be sent to LCD. They are just loaded to GPIO expander data pins, but the LCD RS, RW and E lines are not set at any point for each command nybble, so the commands are not strobed to the LCD.
Answered by Justme on January 4, 2022
1 Asked on December 26, 2020 by mcfudge
1 Asked on December 26, 2020 by a-m-s
1 Asked on December 23, 2020 by whiskerbiscuit
1 Asked on December 22, 2020 by radiofreak1041
1 Asked on December 22, 2020 by mfeinstein
1 Asked on December 22, 2020 by bestqualityvacuum
1 Asked on December 22, 2020 by fab
0 Asked on December 21, 2020 by rocko445
0 Asked on December 21, 2020 by juha-mattila
battery operated current limiting supercapacitor switching losses
1 Asked on December 21, 2020 by tibu-v
1 Asked on December 21, 2020 by user176257
2 Asked on December 20, 2020 by looper
diodes integrated circuit offset operational amplifier resistors
3 Asked on December 20, 2020 by remco-van-gorsel
0 Asked on December 20, 2020 by robg
2 Asked on December 19, 2020 by simonv
Get help from others!
Recent Questions
Recent Answers
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP