Jump to content
43oh

The Chilango power

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by The Chilango power

  1. 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_ */

  2. hello my name is Alejandro Garcia :lol: , I'm from Mexico City and I am an engineer in electronics and communications, my short time working only pics I've used the microchip, I started programming with PIC16F PIC18 then and now the pics32mx, I have developed different types of hardware, my greatest achievement has been a board with color screen 7-inch touch screen with USB host, the heart of the board is a microcontroller pic32mx512.

     

    I have had many desepciones with picsm :cry: and now I want to start using IT mics, I bought my MSP430 Launchpad and a clock eZ430-Chronosy soon acquire a STERALLIS

     

    well I hope to share the little that turn and you know what I did my first show and was managing a 16x2 lcd

     

    Saludos y hasta luego

     

    Note: sorry if I wrote something not good but I'm using google translator I can not speak very good English

×
×
  • Create New...