Manejo de LCD con MSP

Espero que alguien me pueda ayudar con el siguient problema: Requiro hacer un programa con un msp para manejar un lcd 16x2, Espero que alguien m ayude, no sé como mandarl datos al lcd.
 
Hi jask, y que proyectos has realizado con el MSP?
el envio de datos depende del driver del display que utilizas.
:)
 
lo necesitas en ensamblador o en lenguaje c aqui te va en c



#include <string.h>

//Direcciones de la seccion de informacion de la memoria flash
#define HAddInfo_A 0x010ff
#define LAddInfo_A 0x01080
#define HAddInfo_B 0x0107f
#define LAddInfo_B 0x01000

#define LCD_Data P2OUT

#define RELAY1_ON P1OUT |= BIT5 //RELAY1 - P1.5
#define RELAY1_OFF P1OUT &= ~BIT5 //RELAY1 - P1.5
#define RELAY2_ON P1OUT |= BIT6 //RELAY1 - P1.6
#define RELAY2_OFF P1OUT &= ~BIT6 //RELAY1 - P1.6
#define STATUS_LED_ON P2OUT &= ~BIT1 //STATUS_LED - P2.1
#define STATUS_LED_OFF P2OUT |= BIT1 //STATUS_LED - P2.1


// DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
// ======================= === === === === === === === ===
#define Clear_Display 0x01 // 0 0 0 0 0 0 0 1
#define Return_Home 0x02 // 0 0 0 0 0 0 1 *
#define Set_Entry_Mode 0x04 // 0 0 0 0 0 1 I/D S
#define Set_Display 0x08 // 0 0 0 0 1 D C B
#define Set_Cursor_and_Display_Shift 0x10 // 0 0 0 1 S/C R/L * *
#define Set_Function 0x20 // 0 0 1 DL N F * *
#define Set_CGRAM_Address 0x40 // 0 1 A5 A4 A3 A2 A1 A0
#define Set_DDRAM_Address 0x80 // 1 A6 A5 A4 A3 A2 A1 A0
// HD44780 Parameters
// ==================
// Deben pasarse valores de los parámetros, cada vez que se envien
// comandos hacie el display
// Set_Entry_Mode
// ==============
#define Decrement_Address 0x00 // . . . . . . 0 .
#define Increment_Address 0x02 // . . . . . . 1 .
#define Shift_Display_Off 0x00 // . . . . . . . 0
#define Shift_Display_On 0x01 // . . . . . . . 1
// Set_Display
// ===========
#define Display_Off 0x00 // . . . . . 0 . .
#define Display_On 0x04 // . . . . . 1 . .
#define Cursor_Off 0x00 // . . . . . . 0 .
#define Cursor_On 0x02 // . . . . . . 1 .
#define Blink_Off 0x00 // . . . . . . . 0
#define Blink_On 0x01 // . . . . . . . 1
// Set_Cursor_and_Display_Shift
// ============================
#define Cursor 0x00 // . . . . 0 . . .
#define Display_and_Cursor 0x08 // . . . . 1 . . .
#define Left 0x00 // . . . . . 0 . .
#define Right 0x04 // . . . . . 1 . .
// Set_Function
// ============
#define Data_Length_4 0x00 // . . . 0 . . . .
#define Data_Length_8 0x10 // . . . 1 . . . .
#define One_Display_Line 0x00 // . . . . 0 . . .
#define Two_Display_Lines 0x08 // . . . . 1 . . .
#define Font_5x7 0x00 // . . . . . 0 . .
#define Font_5x10 0x04 // . . . . . 1 . .
#define Line2_Offset 0x40 //



// mspdefs.h - msp430 Port and Pinout definitions
//
//
// MSP430 Port
// ======================================
// 7 6 5 4 3 2 1 0 I/O Port
// +---+---+---+---+---+---+---+---+
// |DB7|DB6|DB5|DB4| E | RS| - | - | 2
// +---+---+---+---+---+---+---+---+
//
//If timing is non-critical (no need to check Busy Flag DB7)
//then the R/W line - LCD Pin 5 - can be tied to Ground LOW).

// Port Control Outputs
// =========================================
// Mode Select 7 6 5 4 3 2 1 0
// =============== === === === === === === === ===
#define Data_Mov 0x04 // . . . . . 1 . .
#define Ins_Mov 0x00 // . . . . . 0 . .
// Enable 7 6 5 4 3 2 1 0
// ====== === === === === === === === ===
#define Enable_Low 0x00 // . . . . 0 . . .
#define Enable_High 0x08 // . . . . 1 . . .
//Definición de señales de control mediante pines del micro
#define E_OFF P2OUT &= ~BIT3 // P2.3 = 0
#define E_ON P2OUT |= BIT3 // P2.3 = 1

#define RS_OFF P2OUT &= ~BIT2 // P2.2 = 0
#define RS_ON P2OUT |= BIT2 // P2.2 = 1

void Comienzo();
void validacion(int cl);
void Init_Display(void);
void Init_Ports();



#include "INCLUDES.H"
#include <msp430x14x.h>

//////Inicio de los puertos
void Init_Ports()
{
P2SEL =0; //pines del lcd
P2DIR |=0xff;
P2OUT =0;
P2IE &=0x00;

P1SEL &=0XDF;//Pines Rele
P1DIR |=0X20;
P1OUT &=0:LOL:F;

P4SEL = 0;
P4OUT = 0;
P4DIR = BIT2 | BIT3; //only buzzer pins are outputs
}


void Delay(unsigned int a)
{
int k;
for (k=0 ; k != a; ++k); //9+a*125 ns
}


saludos

void Delayx100us(unsigned int b)
{
int j;
for(j=0; j<b ;j++) Delay(_100us);
}

/////////funcion send char

void SEND_CHAR (unsigned char d)
{ unsigned char temp;
Delay(_100us); //.5ms
temp = d & 0xf0; //get upper nibble
LCD_Data &= 0x0f;
LCD_Data |= temp;
RS_ON; //set LCD to data mode
E_ON; Delay(_10us); E_OFF; //toggle E for LCD
temp = d & 0x0f;
temp = temp << 4; //get down nibble
LCD_Data &= 0x0f;
LCD_Data |= temp;
RS_ON; //set LCD to data mode
E_ON; Delay(_10us); E_OFF; //toggle E for LCD
}

/////////////funcion send comand

void SEND_CMD (unsigned char e)//este es intocable para mandar comandos
{
unsigned char temp;
Delay(_100us);
temp = e & 0xf0; //get upper nibble
LCD_Data &= 0x0f;
LCD_Data |= temp; //send CMD to LCD
RS_OFF; //set LCD to CMD mode
E_ON; Delay(_10us); E_OFF; //toggle E for LCD

temp = e & 0x0f;
temp = temp << 4; //get down nibble
LCD_Data &= 0x0f;
LCD_Data |= temp;
RS_OFF; //set LCD to CMD mode
E_ON; Delay(_10us); E_OFF; //toggle E for LCD
if((e==Clear_Display) || (e==Return_Home))
Delayx100us(1000);
}

//////////inicio del lcd

void Init_Display(void)
{
Delayx100us(250); //esperar 70 ms. Queda en modo 8 bits.
Delayx100us(250);
E_ON; LCD_Data = Set_Function+Data_Length_4+Enable_High;Delay(50); E_OFF;
Delay(500);//esperar cambio a modo 4 bits
SEND_CMD(Set_Function + Data_Length_4 + Two_Display_Lines + Font_5x7);//no basta una
SEND_CMD(Set_Function + Data_Length_4 + Two_Display_Lines + Font_5x7);//la segunda es aceptada
SEND_CMD(Set_Display + Display_On + Cursor_Off + Blink_Off);
SEND_CMD(Clear_Display);Delayx100us(500);
SEND_CMD(Set_Entry_Mode + Increment_Address + Shift_Display_Off);
}

///////funcion mandar string

void SEND_STR(char *Str)
{
unsigned int l,m;
l=strlen(Str);
for(m=0 ; (m<l && m<80) ; m++)
{
if(m==40) SEND_CMD(Set_DDRAM_Address+Line2_Offset);
SEND_CHAR(*(Str+m));
}

}

aqui te dejo el link del proyecto



saludos

este es par el lcd 16*2
 
Última edición:
Gracias cusioso207, oye ya traté de conpilar y me devuelve 2 errores. Ademas el msp430 que uso es el 2111. Espero que me puedas decir como funciona el codigo, respecto a los pines de salida y habilitacion a la LCD
 
Recuerda ponerle un buffer al MSP ya que la gran mayoria de los LCDs con controlador integrado funcionan a 5V, y el MSP trabaja de 2 a 3V...
 
#define E_OFF P2OUT &= ~BIT3 // P2.3 = 0
#define E_ON P2OUT |= BIT3 // P2.3 = 1

#define RS_OFF P2OUT &= ~BIT2 // P2.2 = 0
#define RS_ON P2OUT |= BIT2 // P2.2 = 1


si te fijas en estas lineas aqui se definen para que hagas los ajustes a los pines donde los quieres direccionar
Saludos



#define E_OFF P2OUT &= ~BIT3 // P2.3 = 0
#define E_ON P2OUT |= BIT3 // P2.3 = 1

#define RS_OFF P2OUT &= ~BIT2 // P2.2 = 0
#define RS_ON P2OUT |= BIT2 // P2.2 = 1

si checas P2OUT ES EL PUERTO Y BIT3 ES EL PUERTO2 BIT NUMERO 3 PARA ESTE EJEMPLO
 
Última edición:
Atrás
Arriba