Jump to content


Photo

Issue with transforming from port2 to port1

msp430

  • Please log in to reply
7 replies to this topic

#1 dutyfree

dutyfree

    Noob Class

  • Members
  • 3 posts

Posted 06 February 2017 - 11:51 PM

Hey dear all, I am new at the website, have been searching for the same issue but couldn't really found. I am trying to drive 2*16 lcd on msp430g2553 with code composer.

 

http://www.instructa...nd-Connections/

 

I am using the library above, It actually works fine with the port connections written. What I am trying to do is I want to transform all the ports into port2.

 

P1.0 - D4 Pin11   to P2.0                                    

P1.1 - D5 Pin12   to P2.1                      

P1.2 - D6 Pin13   to P2.2                          

P1.3 - D7 Pin14   to P2.3                         

P1.4 - RS Pin4     to P2.4                          

P1.5 - R/W Pin5   to P2.5
P1.6 - E Pin6        to P2.6

 

The thing I do is that; instead of P1OUT and P1DIR I used P2OUT and P2DIR but it doesn't work, have been trying for a day but no result. Sure that port connections are correct, checked for many times, there must be something I miss about the code. Any help would be appreciated, thank you.



#2 zeke

zeke

    Level 5

  • Members
  • 1,666 posts
  • LocationCalgary, Canada

Posted 06 February 2017 - 11:59 PM

Welcome @dutyfree!

 

There is a lot of small details that could go wrong when you change from Port1 to Port2.

 

Could you do use a favor and post your code so we can see what you are doing?

 

Please use the little blue <> symbol when you are posting your code in your reply message. That will make the code look nice for us to see.


  • dutyfree likes this

"Life is 10% of what happens to me and 90% of how I react to it" - Charles R. Swindoll

Electrons -> randomelectrons.com
Photons -> ninemicron.com


#3 dutyfree

dutyfree

    Noob Class

  • Members
  • 3 posts

Posted 07 February 2017 - 12:17 AM

Thank you for the advice :) @zeke

#ifndef __LCD_H
#define __LCD_H
 
#define DATAREG 		P1OUT |= BIT4 		// P2OUT |= BIT4 
#define COMMANDREG 		P1OUT &= (~BIT4) 	// P2OUT |= BIT4 
#define READ 			P1OUT |= BIT5 		// P2OUT |= BIT5 
#define WRITE 			P1OUT &= (~BIT5) 	// P2OUT &= (~BIT5) 
#define ENABLE_HIGH 	        P1OUT |= BIT6 		// P2OUT |= BIT6
#define ENABLE_LOW 		P1OUT &= (~BIT6) 	// P2OUT &= (~BIT6)  
 
void lcd_delay(unsigned int k); 
void enable_pulse(void);
void lcd_sendcmd(unsigned char cmd); 
void lcd_putch(unsigned char c);	
static void lcd_senddata(unsigned char data); 
void lcd_puts(char *s); 
void lcd_init(void);
void lcd_clear(void); 
static void lcdsetcur(unsigned char cur); 
void lcd_setcursor(unsigned char x, unsigned char y); 
void setcursor_secline(void); 
void setcursor_right(void);
void setcursor_left(void); 
void blinkcursor(void); 
void lcd_disable(void); 
void lcd_enable(void); 


#endif
/*
pin connections
P1.0 - D4 Pin11  	//P2.0 
P1.1 - D5 Pin12		//P2.1
P1.2 - D6 Pin13		//P2.2
P1.3 - D7 Pin14		//P2.2
P1.4 - RS Pin4		//P2.4
P1.5 - R/W Pin5		//P2.5
P1.6 - E Pin6*/		//P2.6

#include <msp430g2553.h>
#include <LCD.h>
unsigned int i,j;

void lcd_delay(unsigned int k)
{
	for(j=0;j<=k;j++){
	for(i=0;i<100;i++);}
}

void enable_pulse(void)
{
	ENABLE_HIGH;
	lcd_delay(2);
	ENABLE_LOW;
}

void lcd_sendcmd(unsigned char cmd)
{
	WRITE;
	COMMANDREG;
	P1OUT = (P1OUT & 0xF0)|((cmd>>4) & 0x0F); 	//P2OUT = (P2OUT & 0xF0)|((cmd>>4) & 0x0F);
	enable_pulse();
	P1OUT = (P1OUT & 0xF0)|(cmd & 0x0F); 		//P2OUT = (P2OUT & 0xF0)|(cmd & 0x0F); 
	enable_pulse();
}

static void lcd_senddata(unsigned char data)
{
	WRITE;
	DATAREG;
	P1OUT = (P1OUT & 0xF0)|((data>>4) & 0x0F);  //P2OUT = (P2OUT & 0xF0)|((data>>4) & 0x0F); 
	enable_pulse();
	P1OUT = (P1OUT & 0xF0)|(data & 0x0F); 		//P2OUT = (P2OUT & 0xF0)|((data>>4) & 0x0F); 
	enable_pulse();
}

void lcd_putch(unsigned char c)
{
	switch (c) {
	
	case '\r':
	lcdsetcur(0);
	break;

	
	case '\n':
	lcdsetcur(0xC0);
	break;


	case '\f':
	lcd_clear();
	break;

	default:
		lcd_senddata(c);
	break;
}}

void lcd_puts(char *s)
{
	while(*s){
	lcd_senddata(*s++);}
}

void lcd_init(void)
{
	P1DIR |= 0xFF;  //P2DIR |= 0xFF;
	P1OUT &= 0x00; 	//P2DIR &= 0x00;
	lcd_sendcmd(0x33);
	lcd_sendcmd(0x32);
	lcd_sendcmd(0x28); 
	lcd_sendcmd(0x0E);
	lcd_sendcmd(0x01); 
	lcd_sendcmd(0x06);
	lcd_sendcmd(0x80); 
}


void lcd_clear()
{
	lcd_sendcmd(0x01); 
	lcd_sendcmd(0x80); 
}

static void lcdsetcur(unsigned char cur)  	
{								
	lcd_sendcmd(0x80 | cur);
}							

void lcd_setcursor(unsigned char x, unsigned char y)
{
	if(y>0 && y<17){
	if (x==1){
		y--; 
	
		lcd_sendcmd(0x80 |(0x80 + y));
	}
	if (x==2){
			y--;
	
		lcd_sendcmd(0xC0 |(0xC0 + y));
		}}

}

void setcursor_secline(void)
{
	lcd_sendcmd(0xC0);
}

void setcursor_right(void)
{
	lcd_sendcmd(0x14);
}

void setcursor_left(void)
{
	lcd_sendcmd(0x10);
}

void blinkcursor(void)
{
	lcd_sendcmd(0xF);
}

void lcd_disable(void)
{
	lcd_sendcmd(0x08);
}

void lcd_enable(void)
{
	lcd_sendcmd(0x0C);
}

This is the .h and .c files I implemented for the 2*16 LCD. The library above works fine, I want to use it in P2 as well as I mentioned on comment lines on the code. I only changed the names of the ports as it is seen but I guess that's not enough.



#4 zeke

zeke

    Level 5

  • Members
  • 1,666 posts
  • LocationCalgary, Canada

Posted 07 February 2017 - 12:40 AM

Okay, I am interested in this section:

#ifndef __LCD_H
#define __LCD_H
 
#define DATAREG 		P1OUT |= BIT4 		// P2OUT |= BIT4 
#define COMMANDREG 		P1OUT &= (~BIT4) 	// P2OUT |= BIT4 
#define READ 			P1OUT |= BIT5 		// P2OUT |= BIT5 
#define WRITE 			P1OUT &= (~BIT5) 	// P2OUT &= (~BIT5) 
#define ENABLE_HIGH 	        P1OUT |= BIT6 		// P1OUT |= BIT6
#define ENABLE_LOW 		P1OUT &= (~BIT6) 	// P1OUT &= (~BIT6)

These three lines look suspicious to me.

#define COMMANDREG 		P1OUT &= (~BIT4) 	// P2OUT |= BIT4 

#define ENABLE_HIGH 	        P1OUT |= BIT6 		// P1OUT |= BIT6
#define ENABLE_LOW 		P1OUT &= (~BIT6) 	// P1OUT &= (~BIT6)

Specifically, I am looking at your commented out code which I understand is what you want to do.

 

Should they be adapted to Port2 somehow?

#define COMMANDREG 		P1OUT &= (~BIT4) 	// P2OUT |= BIT4
                                                                    ^^^^

#define ENABLE_HIGH 	        P1OUT |= BIT6 		// P1OUT |= BIT6
                                                           ^^^^^

#define ENABLE_LOW 		P1OUT &= (~BIT6) 	// P1OUT &= (~BIT6)
                                                           ^^^^^

I put carets underneath the characters that I think are suspicious.

 

What do you think?


"Life is 10% of what happens to me and 90% of how I react to it" - Charles R. Swindoll

Electrons -> randomelectrons.com
Photons -> ninemicron.com


#5 zeke

zeke

    Level 5

  • Members
  • 1,666 posts
  • LocationCalgary, Canada

Posted 07 February 2017 - 02:24 AM

Oh, please tell us more about your circuit.

 

Are you using a LaunchPad?

Which hardware version is it?

Do you about the jumpers that effect the I/O lines?


"Life is 10% of what happens to me and 90% of how I react to it" - Charles R. Swindoll

Electrons -> randomelectrons.com
Photons -> ninemicron.com


#6 dutyfree

dutyfree

    Noob Class

  • Members
  • 3 posts

Posted 08 February 2017 - 05:16 PM

I realized that while writing the code on comment lines I had made mistake, It actually is like this below.

#define DATAREG 		P1OUT |= BIT4 		// P2OUT |= BIT4 
#define COMMANDREG 		P1OUT &= (~BIT4) 	// P2OUT &= (~BIT4)
#define READ 			P1OUT |= BIT5 		// P2OUT |= BIT5 
#define WRITE 			P1OUT &= (~BIT5) 	// P2OUT &= (~BIT5) 
#define ENABLE_HIGH 	        P1OUT |= BIT6 		// P2OUT |= BIT6
#define ENABLE_LOW 		P1OUT &= (~BIT6) 	// P2OUT &= (~BIT6)  

The only thing I changed is writin P1 instead of P2, It works fine on P1 but still doesn't work with the port 2 configuration. I am using launchpad msp430g2(2553). Do you think there may be something about Port2 configuration that Texas set up on hardware, because that is really strange I used port2 for some other applications had no problem or there may be something wrong on the code while writing the port configurations but I still couldn't figure it out. 



#7 NurseBob

NurseBob

    Level 1

  • Members
  • 95 posts
  • LocationSt. Helena, CA

Posted 08 February 2017 - 10:51 PM

I'm wondering, isn't the default configuration for pin 2.6 XIN for a 32kHz clock? I believe you need to change the port to I/O mode via P2SEL?


  • Frida likes this

#8 terjeio

terjeio

    Level 1

  • Members
  • 103 posts
  • LocationNorway

Posted 09 February 2017 - 02:36 PM

@NurseBob Sure have to do that, from table 8.2 in the user guide:

 

"Port Select P2SEL 02Eh Read/write 0C0h with PUC"

 

0Ch means pins 6 and 7 are configured for primary peripheral module function on power up, not i/o.


  • Frida likes this





Also tagged with one or more of these keywords: msp430

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users