Autor Tema: LCD con micro xc167  (Leído 2246 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado miguelito2004

  • PIC10
  • *
  • Mensajes: 1
LCD con micro xc167
« en: 14 de Junio de 2004, 08:30:00 »
Estoy intentando que mandar una cadena a la pantalla de mi LCD, pero no lo consigo.Trabajo con Tasking y agradeceria mucho si alguien me audara a salir de esto.

Gracias

Este es mi programa
//****************************************************************************
// @Module        Project Settings
// @Filename      MAIN.C
// @Project       PROBE.dav
//----------------------------------------------------------------------------
// @Controller    Infineon XC167CI-16F40
//
// @Compiler      Tasking
//
// @Codegenerator 2.1
//
// @Description   This file contains the project initialization function.
//
//----------------------------------------------------------------------------
// @Date          10.06.2004 15:34:26
//
//****************************************************************************

// USER CODE BEGIN (MAIN_General,1)

// USER CODE END



//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"

// USER CODE BEGIN (MAIN_General,2)

#include <absacc.h>
#include <string.h>
#include <stdio.h>
// USER CODE END


//****************************************************************************
// @Macros
//****************************************************************************

// USER CODE BEGIN (MAIN_General,3)

// USER CODE END


//****************************************************************************
// @Defines
//****************************************************************************

// USER CODE BEGIN (MAIN_General,4)


// USER CODE END


//****************************************************************************
// @Typedefs
//****************************************************************************

// USER CODE BEGIN (MAIN_General,5)
//#define LCD_CNTL MVAR (unsigned char,0x800000)
//#define LCD_DATA MVAR (unsigned char,0x800001)
// USER CODE END


//****************************************************************************
// @Imported Global Variables
//****************************************************************************

// USER CODE BEGIN (MAIN_General,6)
   unsigned char x;
   unsigned short *LCD_CNTL;
   unsigned short *LCD_DATA;

//   LCD_CNTL = (unsigned short*)0x800000;
//   LCD_DATA = (unsigned short*)0x800002;

// USER CODE END


//****************************************************************************
// @Global Variables
//****************************************************************************

// USER CODE BEGIN (MAIN_General,7)


// USER CODE END


//****************************************************************************
// @External Prototypes
//****************************************************************************

// USER CODE BEGIN (MAIN_General,8)

// USER CODE END


//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************

// USER CODE BEGIN (MAIN_General,9)
void wait(unsigned int w);
void write_string(char*s, unsigned char line);

// USER CODE END


//****************************************************************************
// @Function      void MAIN_vInit(void)
//
//----------------------------------------------------------------------------
// @Description   This function initializes the microcontroller.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          10.06.2004
//
//****************************************************************************

// USER CODE BEGIN (Init,1)

// USER CODE END

void MAIN_vInit(void)
{
  // USER CODE BEGIN (Init,2)

  // USER CODE END

  ///  -----------------------------------------------------------------------
  ///  Configuration of the System Clock:
  ///  -----------------------------------------------------------------------
  ///  - VCO clock used, input clock is connected
  ///  - input frequency is 8 MHz
  ///  - VCO output frequency 100 .. 150 MHz
  ///  - system clock is 20 MHz

  MAIN_vUnlockProtecReg();       // unlock write security
  PLLCON         =  0x7814;      // load PLL control register


  //// -----------------------------------------------------------------------
  //// Begin of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------
  ///  All following settings must be set in the start-up file. You can use
  ///  DAvE"s project file (*.dpt) to include this register values into your
  ///  compiler EDE.

    ///  ---------------------------------------------------------------------
    ///  Initialization of the CPUCON1 Register:
    ///  ---------------------------------------------------------------------
    ///  - space between two vectors is 2 words
    ///  - DISWDT executable until End of Init
    ///  - segmentation is enabled
    ///  - switch context is interruptible
    ///  - branch prediction is enabled
    ///  - zero cycle jump function is enabled

    //// this register must be set in the start-up file
    //// CPUCON1  =  0x0007

    ///  ---------------------------------------------------------------------
    ///  Initialization of the VECSEG Register:
    ///  ---------------------------------------------------------------------
    ///  - start from external memory

    //// this register must be set in the start-up file
    //// VECSEG  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON0 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON0  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON1 Register:
    ///  ---------------------------------------------------------------------
    ///  clock prescaler for system is fpll / 1

    //// this register must be set in the start-up file
    //// SYSCON1  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of the SYSCON3 Register:
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// SYSCON3  =  0x0000

    ///  ---------------------------------------------------------------------
    ///  Initialization of EBC
    ///  ---------------------------------------------------------------------

    //// this register must be set in the start-up file
    //// EBCMOD1  =  0x0000

    ///  EBC is enabled
    ///  pin #BHE is enabled
    ///  #WR and #BHE retain their normal function
    ///  pin ALE is enabled
    ///  as segment address are 2 pins enabled ( A[17] .. A[16] )
    ///  #CS2 .. #CS0 are enabled
    ///  pin #READY is enabled
    ///  #READY is active low
    ///  bus arbitration is disabled, P6.7 .. P6.5 may used for general
    ///  purpose IO

    //// this register must be set in the start-up file
    //// EBCMOD0  =  0x0032

    ///  ---------------------------------------------------------------------
    ///  ---------- chip select 0 is enabled ----------
    ///  ---------------------------------------------------------------------
    ///  - 16-bit Multiplexed Bus
    ///  access time is controlled by bitfield PHE0

    //// this register must be set in the start-up file
    //// FCONCS0  =  0x0031

    ///  Phase A: 3 clock cycles
    ///  Phase B: 1 clock cycles
    ///  Phase C: 0 clock cycles
    ///  Phase D: 0 clock cycles
    ///  Phase E: 10 clock cycles
    ///  Read Phase F: 0 clock cycles
    ///  Write Phase F: 3 clock cycles

    //// this register must be set in the start-up file
    //// TCONCS0  =  0x6243

    ///  ---------------------------------------------------------------------
    ///  ---------- chip select 1 is disabled ----------
    ///  ---------------------------------------------------------------------


    ///  ---------------------------------------------------------------------
    ///  ---------- chip select 2 is disabled ----------
    ///  ---------------------------------------------------------------------


    ///  ---------------------------------------------------------------------
    ///  ---------- chip select 3 is enabled ----------
    ///  ---------------------------------------------------------------------
    ///  - 16-bit Multiplexed Bus
    ///  access time is controlled by bitfield PHE3

    //// this register must be set in the start-up file
    //// FCONCS3  =  0x0031

    ///  Phase A: 3 clock cycles
    ///  Phase B: 2 clock cycles
    ///  Phase C: 0 clock cycles
    ///  Phase D: 0 clock cycles
    ///  Phase E: 32 clock cycles
    ///  Read Phase F: 3 clock cycles
    ///  Write Phase F: 3 clock cycles

    //// this register must be set in the start-up file
    //// TCONCS3  =  0x7FC7

    ///  address range size selection: 4 KByte
    ///  start address (A23..A0): 0x800000

    //// this register must be set in the start-up file
    //// ADDRSEL3  =  0x8000

    ///  ---------------------------------------------------------------------
    ///  ---------- chip select 4 is disabled ----------
    ///  ---------------------------------------------------------------------


  //// -----------------------------------------------------------------------
  //// End of Important Settings for the Start-Up File
  //// -----------------------------------------------------------------------


  //   -----------------------------------------------------------------------
  //   Initialization of the Peripherals:
  //   -----------------------------------------------------------------------

  // USER CODE BEGIN (Init,3)

  // USER CODE END

  //   globally enable interrupts
  PSW_IEN        =  1;          

} //  End of function MAIN_vInit


//****************************************************************************
// @Function      void MAIN_vUnlockProtecReg(void)
//
//----------------------------------------------------------------------------
// @Description   This function makes it possible to write one protected
//                register. After calling of this function and write on the
//                protected register is the security level set to low
//                protected mode.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          10.06.2004
//
//****************************************************************************

// USER CODE BEGIN (UnlockProtecReg,1)

// USER CODE END

void MAIN_vUnlockProtecReg(void)
{
  ubyte ubPASSWORD;

  if((SCUSLS & 0x1800) == 0x0800)      // if low protected mode
  {

    ubPASSWORD = SCUSLS & 0x00FF;
    ubPASSWORD = ~ubPASSWORD;
    SCUSLC = 0x8E00 | ubPASSWORD;      // command 4

  }  // end if low protected mode

  if((SCUSLS & 0x1800) == 0x1800)      // if write protected mode
  {
    SCUSLC = 0xAAAA;                   // command 0
    SCUSLC = 0x5554;                   // command 1

    ubPASSWORD = SCUSLS & 0x00FF;
    ubPASSWORD = ~ubPASSWORD;

    SCUSLC = 0x9600 | ubPASSWORD;      // command 2
    SCUSLC = 0x0800;                   // command 3; new PASSWOR is 0x00

    ubPASSWORD = SCUSLS & 0x00FF;
    ubPASSWORD = ~ubPASSWORD;
    SCUSLC = 0x8E00 | ubPASSWORD;      // command 4

  }  // end if write protected mode

} //  End of function MAIN_vUnlockProtecReg


//****************************************************************************
// @Function      void main(void)
//
//----------------------------------------------------------------------------
// @Description   This is the main function.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          10.06.2004
//
//****************************************************************************

// USER CODE BEGIN (Main,1)



// USER CODE END

void main(void)
{  
 // USER CODE BEGIN (Main,2)
    unsigned char x;
    unsigned short *LCD_CNTL;
    unsigned short *LCD_DATA;
   LCD_CNTL = (unsigned short*)0x800000;
   LCD_DATA = (unsigned short*)0x800002;
 
     x=0x38;
   wait(0x0020);
   (*LCD_CNTL) = x;
   wait(0x000A);
   (*LCD_CNTL) = x;
   wait(0x000A);
   (*LCD_CNTL) = x;
   wait(0x000A);

     //Display Initialisierung

   (*LCD_CNTL) = x;
   wait(0x000A);

   //Display Aus
   (*LCD_CNTL) = 0x06;
   wait(0x000A);

   //clear Display
   (*LCD_CNTL) = 0x0E;
   wait(0x000A);

   //Display Ein
   (*LCD_CNTL) = 0x01;
   wait(0x000A);
MAIN_vInit();

// USER CODE BEGIN (Main,4)   


// USER CODE END

  while(1)
  {
  write_string("hola",1);
  }



  // USER CODE END



} //  End of function main


// USER CODE BEGIN (MAIN_General,10)
void write_string (char*s,unsigned char line)
   {
   unsigned int i;
   if (line ==1)
   (*LCD_CNTL) = 0x80;
   if (line==2)
   (*LCD_CNTL) = 0xC0;
   wait(3000);

      for (i=0;i<strlen(s);i++)
      {
      (*LCD_DATA) = s;
      wait(30);
      }
   }   

void  wait (unsigned int w)
{
unsigned int a,b;
   for (a=0;a<w;a++)
   {
   for(b=0;b<0x1388;b++);
   }
return;   
   
}

// USER CODE END



 

anything