The Chilango power 6 Posted August 28, 2012 Share Posted August 28, 2012 Hola les muestro mi primer proyecto con MSP430 LaunchPad es un simple LCD 16X2 #include #include "LCD_v1.h" #define LED1 BIT0 #define LED2 BIT6 #define B1 BIT3 //void setup(void); unsigned char i; typedef char* cadena; int main(void) { cadena string; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; P1REN = 0x00; P1SEL = 0x00; P1IE = 0x00; Inicializa_LCD(); while(1){ Comando_LCD(CLEAR); Dato_String_LCDEx(LN1," HOLA MUNDO "); Dato_String_LCDEx(LN2, " **MSP430** "); delay_ms(2000); Comando_LCD(CLEAR); Dato_String_LCDEx(LN1," HECHO POR "); Dato_String_LCDEx(LN2,"=> THE CHILANGO POWER"); for(i = 0;i < 8;i++){ Comando_LCD(SHIFT_DISP_RIGHT); delay_ms(400); } for(i = 0;i < 14;i++){ Comando_LCD(SHIFT_DISP_LEFT); delay_ms(400); } delay_ms(2000); string = "MSP430 LaunchPad "; Comando_LCD(CLEAR); while(*string){ Dato_LCD(*string++); delay_ms(300); } string = "DATE 27/08/2012"; GoToXY(2,1); while(*string){ Dato_LCD(*string++); delay_ms(300); } delay_ms(1000); for(i=0;i<5;i++){ Comando_LCD(DOFF); delay_ms(200); Comando_LCD(DON); delay_ms(200); } Comando_LCD(DON); delay_ms(1500); } } /* * LCD_V1.c * * Created on: 13/08/2012 * Author: THE CHILANGO POWER */ #include "LCD_V1.h" //********************************************************** /* Inicializacion del LCD segun fabricante */ //********************************************************** void Inicializa_LCD(void){ PDIR_LCD = 0; POUT_LCD = 0; delay_ms(100); PDIR_LCD |= PDIR_BIT1_LCD | PDIR_BIT2_LCD | PDIR_BIT3_LCD | PDIR_BIT4_LCD; PDIR_LCD |= PDIR_PIN_RS | PDIR_PIN_E; POUT_LCD &= ~POUT_PIN_E; POUT_LCD &= ~POUT_PIN_RS; Flex_port(0X03); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &= ~POUT_PIN_E; delay_ms(5); Flex_port(0X03); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &= ~POUT_PIN_E; delay_us(160); Flex_port(0X03); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &= ~POUT_PIN_E; delay_us(160); Flex_port(NIBLE); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &= ~POUT_PIN_E; delay_us(160); Comando_LCD(0x28); Comando_LCD(0x08); Comando_LCD(0x01); // Comando_LCD(LINES_5X7 & FOUR_BIT); // Comando_LCD(DON & CURSOR_OFF & BLINK_OFF); // Comando_LCD(CLEAR); Comando_LCD(0x06); /* Entry Mode Set */ /* Incremento del cursor */ Comando_LCD(0x0C); return; } //********************************************************** /* Indica al LCD comandos */ //********************************************************** void Comando_LCD(unsigned char dato) { volatile unsigned char temp; /* variable auxiliar */ //delay_ms(10); /* Retardo de 10 mseg. */ POUT_LCD &=~POUT_PIN_RS; temp = dato; /* Respaldo del dato original */ dato = dato >> 4; /* Corrimiento del nible alto */ Flex_port(dato); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &=~POUT_PIN_E; Flex_port(temp); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &=~POUT_PIN_E; delay_us(2000); return; } //********************************************************** /* Manda datos al LCD */ //********************************************************** void Dato_LCD(unsigned char dato) { volatile unsigned char temp; /* variable auxiliar */ POUT_LCD |= POUT_PIN_RS; // delay_ms(10); /* Retardo de 10 mseg. */ temp = dato; /* Respaldo del dato original */ dato = dato >> 4; /* Corrimiento del nible alto */ Flex_port(dato); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &=~POUT_PIN_E; Flex_port(temp); delay_us(50); POUT_LCD |= POUT_PIN_E; delay_us(1); POUT_LCD &=~POUT_PIN_E; POUT_LCD &=~ POUT_PIN_RS; delay_us(50); return; } //********************************************************** // Escribe una cadena desde memoria de programa al LCD //********************************************************** void Datos_LCD(const char *buffer) { while(*buffer) // Write data to LCD up to null { Dato_LCD(*buffer); // Write character to LCD buffer++; // Increment buffer } return; } //********************************************************** // Escribe una cadena desde memoria de datos al LCD //********************************************************** void Dato_String_LCD(char *buffer) { while(*buffer) // Write data to LCD up to null { Dato_LCD(*buffer); // Write character to LCD buffer++; // Increment buffer } return; } void Flex_port(unsigned char data){ POUT_LCD &= ~BIT1_LCD; POUT_LCD &= ~BIT2_LCD; POUT_LCD &= ~BIT3_LCD; POUT_LCD &= ~BIT4_LCD; if(data & BIT0)POUT_LCD |= BIT1_LCD; if(data & BIT1)POUT_LCD |= BIT2_LCD; if(data & BIT2)POUT_LCD |= BIT3_LCD; if(data & BIT3)POUT_LCD |= BIT4_LCD; return; } void Dato_String_LCDEx(unsigned char xLine, char *buffer) { Comando_LCD(xLine); while(*buffer) // Write data to LCD up to null { Dato_LCD(*buffer); // Write character to LCD buffer++; // Increment buffer } return; } void Dato_LCDEx(unsigned char xLine, const char *buffer) { Comando_LCD(xLine); while(*buffer) // Write data to LCD up to null { Dato_LCD(*buffer); // Write character to LCD buffer++; // Increment buffer } return; } void GoToXY(unsigned char Line, unsigned char Position) { switch(Line) { case 1: Position += 128; Comando_LCD(Position); break; case 2: Position +=167; Comando_LCD(Position); break; } return; } void clear_LCD(void){ Dato_String_LCDEx(LN1," "); Dato_String_LCDEx(LN2," "); GoToXY(1,0); return; } void delay_us(unsigned int time){ while(--time)__delay_cycles (1); return; } void delay_ms(unsigned int time){ while(--time)__delay_cycles (1000); return; } #ifndef LCD_V1_H_ #define LCD_V1_H_ #include /* * File: LCD_v1.h * Author: THE CHILANGO POWER * * Created on 13 de julio de 2012, 03:32 PM */ // Manejo de un Display de Cristal Liquido LCD 16X4 // de 16 caracteres por 4 lineas, con una interface // de 4 lineas: // // Conexiones del LCD al Microcontrolador #define POUT_LCD P1OUT #define PDIR_LCD P1DIR #define POUT_PIN_RS BIT0 // Define la Columna 1 #define POUT_PIN_E BIT1 // Define la Columna 3 #define PDIR_PIN_RS BIT0 // Define la Columna 1 #define PDIR_PIN_E BIT1 // Define la Columna 3 #define BIT1_LCD BIT4 #define BIT2_LCD BIT5 #define BIT3_LCD BIT6 #define BIT4_LCD BIT7 #define PDIR_BIT1_LCD BIT4 #define PDIR_BIT2_LCD BIT5 #define PDIR_BIT3_LCD BIT6 #define PDIR_BIT4_LCD BIT7 /* Configuracion del Display y cursor */ #define DON 0X0F //0b00001111 /* Display encendido */ #define DOFF 0X0B //0b00001011 /* Display apagado */ #define CURSOR_HOME 0X02 //0b00000010 /* Cursor encendido */ #define CURSOR_ON 0X0F //0b00001111 /* Cursor encendido */ #define CURSOR_OFF 0X0C //0b00001100 /* Cursor apagado */ #define BLINK_ON 0X0F //0b00001111 /* Cursor con parpadeo */ #define BLINK_OFF 0X0E //0b00001110 /* Cursor sin parpadeo */ #define CLEAR 0X01 //0b00000001 /* Display encendido */ /* Modo de entrada */ #define INCREMENT 0X06 //0b00000110 /* Incrementa la posicion del cursor */ #define DECREMENT 0X04 //0b00000100 /* Decrementa la posicion del cursor */ /* Configuracion de los desplazamientos del cursor y del Display*/ #define SHIFT_CUR_LEFT 0X13 //0b00010011 /* Corrimiento del cursor a la izquierda */ #define SHIFT_CUR_RIGHT 0X17 //0b00010111 /* Corrimiento del cursor a la derecha */ #define SHIFT_DISP_LEFT 0X1B //0b00011011 /* Corrimiento del display a la izquierda */ #define SHIFT_DISP_RIGHT 0X1F //0b00011111 /* Corrimiento del display a la derecha */ /* Funciones de inicializacion */ #define NIBLE 0X02 //0b00000010 /* interface a 4 bits */ #define FOUR_BIT 0X2F //0b00101111 /* Interface a 4-bit */ #define EIGHT_BIT 0X3F //0b00111111 /* Interface a 8-bit */ #define LINE_5X7 0X33 //0b00110011 /* Una linea, caracter 5x7 */ #define LINE_5X10 0X37 //0b00110111 /* Una linea, caracter 5x10 */ #define LINES_5X7 0X3B //0b00111011 /* Dos lineas. character 5x7 */ /* Lineas de trabajo */ #define DDRAM_LINEA_1 0X80 //0b10000000 /* Linea 1 */ #define DDRAM_LINEA_2 0XC0 //0b11000000 /* Linea 2 */ #define DDRAM_LINEA_3 0X90 //0b10010000 /* Linea 3 */ #define DDRAM_LINEA_4 0XD0 //0b11010000 /* Linea 4 */ #define LN1 DDRAM_LINEA_1 #define LN2 DDRAM_LINEA_2 /// Configuracion del puerto // /////////////////////////////////////////////////////////////////////////////// //Prototipos de funciones /////////////////////////////////////////////////////////////////////////////// void Flex_port(unsigned char data); void Inicializa_LCD(void); /* Inicializa LCD */ void Comando_LCD(unsigned char dato); /* Indica al LCD un comando */ void Dato_LCD(unsigned char dato); /* Indica al LCD un caracter */ void Datos_LCD(const char *buffer); /* escribe una cadena desde la memoria de programa al LCD */ void Dato_String_LCD(char *buffer); /* escribe una cadena desde la memoria de datos al LCD */ void Dato_String_LCDEx(unsigned char xLine, char *buffer); void Dato_LCDEx(unsigned char xLine, const char *buffer); void GoToXY(unsigned char Line, unsigned char Position); void delay_us(unsigned int time); void clear_LCD(void); void delay_ms(unsigned int time); #endif /* LCD_V1_H_ */ larsie, Diego Herrera, jsolarski and 3 others 6 Quote Link to post Share on other sites
bluehash 1,581 Posted August 28, 2012 Share Posted August 28, 2012 Welcome to 43oh. I've moved your project to the Projects section. Thanks for sharing! Quote Link to post Share on other sites
Diego Herrera 0 Posted January 28, 2013 Share Posted January 28, 2013 Me gustan mucho los micros de Texas, muy interesante el proyecto. Con que versi Quote Link to post Share on other sites
roadrunner84 466 Posted January 28, 2013 Share Posted January 28, 2013 Hi Diego, the actual version of the launchpad shouldn't really matter, as it is mere a programmer and a bunch of pins. For example the 1.4 and 1.5 mainly differ in the way the serial connection is patched on the jumpers. I don't know what version of the value line microcontroller is used in this project. Just try to load it in a small msp and see if it works ;-) The only cases when it doesn't is when you either miss peripherals our run out of memory (RAM or flash). I'm not sure about the language policy on this forum, but not all people understand Spanish, English is kind of the default language on this forum and almost all websites not targeting a single country. Quote Link to post Share on other sites
cde 334 Posted January 29, 2013 Share Posted January 29, 2013 Me gustan mucho los micros de Texas, muy interesante el proyecto. Con que versi Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.