Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Proper method for sending data in output Ports

$
0
0

I was working on interfacing of LCD (16x2) with msp430g2553 and I came up with following code.

The code is working well.But I have a problem with it.

If i change P1OUT= to  P1OUT|=  the code doesn't work. what's the reason behind this.

main.c

#include <msp430.h>
#include "byte.h"

int main()
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
lcd_init();
lcd_data('A');
return 0;
}

* byte.c
*
* Created on: Nov 8, 2017
* Author: AmitKumar
*/
#include <msp430.h>
#include "byte.h"

#define D0 BIT0
#define D1 BIT1
#define D2 BIT2
#define D3 BIT3
#define RS BIT4
#define EN BIT5
void lcd_init()
{
P1DIR|=D0+D1+D2+D3+RS+EN;
P1OUT|=D0+D1+D2+D3+RS+EN;
lcd_command(0x33);
lcd_command(0x32);
lcd_command(0x28);
lcd_command(0x0E);
lcd_command(0x01);
lcd_command(0x06);
lcd_command(0x80);
}

void lcd_command(unsigned char a)
{
int rs;
rs=0;
lcd_write(a,rs);
}
void lcd_data(unsigned char a)
{
int rs;
rs=1;
lcd_write(a,rs);
}
void lcd_write(unsigned char byte,int rs)
{
if(rs==0)
{
P1OUT&=~RS;
}
else
{
P1OUT|=RS;
}
P1OUT=((P1OUT & 0XF0)|((byte & 0xF0)>>4));   //(here is problem)
P1OUT|=EN;
P1OUT&=~EN;
__delay_cycles(3000);
P1OUT=((P1OUT & 0XF0)|(byte & 0x0F));  //(here is the problem)
P1OUT|=EN;
P1OUT&=~EN;
__delay_cycles(3000);


}

 

byte.h
*
* Created on: Nov 8, 2017
* Author: AmitKumar
*/

#ifndef BYTE_H_
#define BYTE_H_
extern void lcd_init();
extern void lcd_write(unsigned char,int);
extern void lcd_command(unsigned char);
extern void lcd_data(unsigned char);

#endif /* BYTE_H_ */


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>