Autor Tema: Explorer 16 y QVGA: Primeros Pasos  (Leído 42479 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #30 en: 29 de Diciembre de 2007, 10:18:27 »
Y, como nó, ahora viene el mismo Winky del led pero sin delay, haciendo uso de la interrupción del Timer1. (Nota: Estoy estudiando todo el tema de la configuración del Timer1 y mas adelante os pondré los resultados de mis desvelos)

Código: C#
  1. /**********************************************************************
  2. * © 2007 PicManía By RedRaven
  3. *        http://picmania.garcia-cuervo.net
  4. *
  5. * FileName:        main_wink_int_timer1.c
  6. * Dependencies:    p33FJ256GP710.h
  7. * Processor:       dsPIC33F
  8. * Compiler:        MPLAB® C30 v2.01 or higher
  9. *
  10. * Wink Led Port A
  11. *
  12. * C30 Optimization Level: -O1
  13. *
  14. *********************************************************************
  15. * The Processor starts with the Internal oscillator without PLL enabled
  16. * and then the Clock is switched to PLL Mode.
  17. *********************************************************************/
  18. #include <p33FJ256GP710.h>
  19.  
  20. _FOSCSEL(FNOSC_FRC);                           
  21. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF  & POSCMD_XT);        // Clock Switching Enabled and Fail Safe Clock Monitor is disabled
  22.                                                                                         // OSC2 Pin Function: OSC2 is Clock Output
  23.                                                                                         // Primary Oscillator Mode: XT Crystal
  24. _FWDT(FWDTEN_OFF);                                                         // Watchdog Timer Enabled/disabled by user software
  25.  
  26. unsigned int Count;
  27.  
  28. void __attribute__((interrupt,no_auto_psv)) _T1Interrupt( void ){
  29.        
  30.     IFS0bits.T1IF = 0;
  31.     T1CONbits.TON = 0;
  32.     Count++;
  33.     if(Count == 500){
  34.         Count = 0;  
  35.         LATAbits.LATA1 = ~LATAbits.LATA1;                  
  36.     }
  37.     TMR1          = 0;
  38.     T1CONbits.TON = 1;  // reset Timer 1 interrupt flag
  39. }
  40.  
  41. void InitClock() {
  42.         PLLFBD                  = 38; // M  = 40
  43.         CLKDIVbits.PLLPOST = 0; // N1 =  2
  44.         CLKDIVbits.PLLPRE   = 0; // N2 =  2
  45.         OSCTUN                = 0;
  46.         RCONbits.SWDTEN   = 0;
  47.         // Clock switch to incorporate PLL
  48.         __builtin_write_OSCCONH(0x01);          // Initiate Clock Switch to FRC with PLL (NOSC=0b001)
  49.         __builtin_write_OSCCONL(0x01);          // Start clock switching while (OSCCONbits.COSC != 0b001); Wait for Clock switch to occur
  50.         while(OSCCONbits.LOCK != 1) {};
  51. }
  52.  
  53. void Init_Timer1( void ){
  54.  
  55.     T1CON         = 0;      // Timer reset
  56.     IFS0bits.T1IF = 0;      // Reset Timer1 interrupt flag
  57.     IPC0bits.T1IP = 6;      // Timer1 Interrupt priority level=4
  58.     IEC0bits.T1IE = 1;      // Enable Timer1 interrupt
  59.     TMR1=  0x0000;     
  60.     PR1 =  0xFFFF;          // Timer1 period register = ?????
  61.     T1CONbits.TON = 1;      // Enable Timer1 and start the counter
  62. }
  63.  
  64. int main(void){
  65.        
  66.     RCONbits.SWDTEN=0; // Disable Watch Dog Timer
  67.     InitClock();               // This is the PLL settings
  68.     Init_Timer1();           //  Init Timer1
  69.  
  70.     //Initialize the Ports All PORTA Output
  71.     TRISA = 0x0000;
  72.     LATA  = 0x0000;
  73.     PORTA = 0x0000;
  74.  
  75.     while(1){
  76.        
  77.     };
  78. }
« Última modificación: 30 de Diciembre de 2007, 12:02:44 por RedPic »
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania


Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #32 en: 29 de Diciembre de 2007, 11:00:06 »
Muchas gracias Manolo. Voy a estudiarlos con detenimiento y admiración por quien ha recorrido antes el camino al que yo ahora me estoy enfrentando.  :mrgreen:
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado blackcat

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 600
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #33 en: 30 de Diciembre de 2007, 03:11:25 »
Tenes que seleccionar en debugger al ICD2, en programmer no tiene que estar seleccionado ninguno ... bueno de todas formas cuando selecciones el ICD2 del lado debugger se desactiva automaticamente del lado programmer ... Ahora ves un cuadrito que dice RELEASE ... dale click y selecciona DEBUG ... ahora recompila el codigo y luego dale click al icono de PLAY ... entonces vas a ver todo el potencial de ICD2!!!!!

Podes poner hasta 4 breakpoints en cualquier parte del codigo para detener el programa y con la ventana de WATCH podes ver el estado de TODOS los registros y la memoria .... TODO ESTO CORRIENDO DIRECTAMENTE DEL DSPIC ....

GENIAL ... NO??? Por lo menos es una buena herramienta !
Control Automático, DSP & Microcontroladores

Desconectado blackcat

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 600
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #34 en: 30 de Diciembre de 2007, 03:46:46 »
Hola no se porque no las habia subido ... pero al fin que ya el pic no solo sirve para encender y apagar LEDS  :D :D ... lastima que la libreria es solo para pics 24 y no dspics ... hay que esperar a que microchip lance esa version....





« Última modificación: 30 de Diciembre de 2007, 04:02:09 por blackcat »
Control Automático, DSP & Microcontroladores

Desconectado blackcat

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 600
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #35 en: 30 de Diciembre de 2007, 04:14:01 »
INSISTO NUEVAMENTE ....  queres sacarle el maximo provecho a tu pic ??? ... usa:

http://www.micrium.com/microchip/index.html 

Con un RTOS te das cuenta que un micro puede hacer mucho mas de lo que te imaginas...



« Última modificación: 30 de Diciembre de 2007, 04:19:48 por blackcat »
Control Automático, DSP & Microcontroladores

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #36 en: 30 de Diciembre de 2007, 12:01:02 »
Otro primer paso más. Ahora le toca al conversor AD del dsPIC. En este ejemplo utilizamos el Potenciometro conectado a RA5 (el cursor) y sus extremos entre Vdd y Vss.

Vamos a realizar de forma continua la conversión y vamos a implementar una especie de VUmeter con los 8 leds del PORTA. Con el POT el extremo de Vss apagaremos todos los Leds y en el extremo contrario, a Vdd, los encenderemos todos, con los distintos puntos intermedios encendiendo tantos leds como le toquen.

En este ejemplo configuramos la conversión AD, activamos la Interrupción de dicha conversión y no utilizamos el DMA. O sea lo mas simple posible, que ya habrá tiempo para complicarse la vida.

Código: C#
  1. /**********************************************************************
  2. * © 2007 PicManía By RedRaven
  3. *        http://picmania.garcia-cuervo.net
  4. *
  5. * FileName:        main_ADC_volts_for_Leds.c
  6. * Dependencies:    p33FJ256GP710.h
  7. * Processor:       dsPIC33F
  8. * Compiler:        MPLAB® C30 v2.01 or higher
  9. *
  10. * Wink Led Port A
  11. *
  12. * C30 Optimization Level: -O1
  13. *
  14. **********************************************************************/
  15.  
  16. #include "p33FJ256GP710.h"
  17. #include "delay.h"
  18.  
  19. _FOSCSEL(FNOSC_PRIPLL);
  20. _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
  21. _FWDT(FWDTEN_OFF);
  22.  
  23.  
  24. volatile unsigned int volts_value=0;
  25. volatile unsigned int flag_volts_value=0;
  26.  
  27.  
  28. void init_clock(void){
  29.  
  30.         //The settings below set up the oscillator and PLL for 16 MIPS
  31.         PLLFBD = 0x00A0;
  32.         CLKDIV = 0x0048;
  33. }
  34.  
  35. void init_leds(void){
  36.  
  37.         unsigned int i;
  38.  
  39.         LATA  = 0xFF00;
  40.         TRISA = 0xFF00;
  41.  
  42.         for(i=0; i<3; i++){
  43.                 LATA = 0xFFFF;
  44.                 Delay(Delay_5mS_Cnt * 20);
  45.                 LATA = 0xFF00;
  46.                 Delay(Delay_5mS_Cnt * 20);
  47.         }
  48.  
  49. }
  50.  
  51. void init_ADC( void )
  52. {
  53.  
  54.         /* set port configuration here */              
  55.         AD1PCFGLbits.PCFG5 = 0;         // ensure AN5/RB5 is analog (Analog Pot)
  56.         /* set channel scanning here, auto sampling and convert, with default read-format mode */
  57.         AD1CON1 = 0x00E4;
  58.         /* select 12-bit, 1 channel ADC operation */
  59.         AD1CON1bits.AD12B = 1;
  60.         /* No channel scan for CH0+, Use MUX A, SMPI = 1 per interrupt, Vref = AVdd/AVss */
  61.         AD1CON2 = 0x0000;
  62.         /* Set Samples and bit conversion time */
  63.         AD1CON3 = 0x032F;
  64.         /* set channel scanning here for AN5 */
  65.         AD1CSSL = 0x0000;
  66.         /* channel select AN5 */
  67.         AD1CHS0 = 0x0005;
  68.         /* reset ADC interrupt flag */
  69.         IFS0bits.AD1IF = 0;          
  70.         /* enable ADC interrupts, disable this interrupt if the DMA is enabled */        
  71.         IEC0bits.AD1IE = 1;      
  72.         /* turn on ADC module */
  73.         AD1CON1bits.ADON = 1;  
  74. }
  75.  
  76. void __attribute__((interrupt,no_auto_psv)) _ADC1Interrupt(void){
  77.        
  78.         if(flag_volts_value==0){
  79.                 volts_value = ADC1BUF0; // Save off the RP5 Potentiometer data            
  80.                 flag_volts_value=1;             // set flag to update Leds
  81.         }
  82.         IFS0bits.AD1IF = 0;             // reset ADC interrupt flag
  83. }
  84.  
  85.  
  86. void volts_value_to_leds(void){
  87.  
  88.        
  89.         unsigned int scala,leds;
  90.  
  91.         scala = (unsigned int) volts_value * 0x0007 / 0x0C00;
  92.         leds  = scala;
  93.  
  94.         LATA = 0xFF00;
  95.         if(leds>0) LATA += 0b00000001;
  96.         if(leds>1) LATA += 0b00000010;
  97.         if(leds>2) LATA += 0b00000100;
  98.         if(leds>3) LATA += 0b00001000;
  99.         if(leds>4) LATA += 0b00010000;
  100.         if(leds>5) LATA += 0b00100000;
  101.         if(leds>6) LATA += 0b01000000;
  102.         if(leds>7) LATA += 0b10000000;
  103. }
  104.  
  105.  
  106. int main ( void ){
  107.  
  108.        
  109.     RCONbits.SWDTEN=0; // Disable Watch Dog Timer
  110.  
  111.         init_clock();
  112.         init_leds();
  113.         init_ADC();
  114.      
  115.        
  116.     /* Infinite Loop */
  117.     while(1){
  118.                 if(flag_volts_value==1){
  119.                         flag_volts_value=0;
  120.                         volts_value_to_leds();
  121.                 }
  122.         };
  123. }

Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #37 en: 30 de Diciembre de 2007, 19:49:44 »
Bueno, continuamos con nuestras pruebas. Ahora el mas simple "Hello Word" en el LCD. Para ello necesitamos los módulos lcd.c y sus prototipos en lcd.h que adjunto mas abajo.  :mrgreen:



Código: C#
  1. /**********************************************************************
  2. * © 2007 PicManía By RedRaven
  3. *        http://picmania.garcia-cuervo.net
  4. *
  5. * FileName:        main_LCD_Hello_World.c
  6. * Dependencies:    p33FJ256GP710.h
  7. * Processor:       dsPIC33F
  8. * Compiler:        MPLAB® C30 v2.01 or higher
  9. *
  10. * Present "Hello World" message
  11. *
  12. * C30 Optimization Level: -O1
  13. *
  14. **********************************************************************/
  15.  
  16. #include "p33FJ256GP710.h"
  17. #include "lcd.h"
  18.  
  19. _FOSCSEL(FNOSC_PRIPLL);
  20. _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
  21. _FWDT(FWDTEN_OFF);
  22.  
  23. int main(void){
  24.  
  25.     char mytext1[] = " dsPIC33F - LCD ";
  26.     char mytext2[] = "  Hello World   ";
  27.  
  28.     char *pText1=&mytext1[0];
  29.     char *pText2=&mytext2[0];
  30.        
  31.     //The settings below set up the oscillator and PLL for 16 MIPS
  32.     PLLFBD = 0x00A0;
  33.     CLKDIV = 0x0048;
  34.     // Initialize LCD Display
  35.     Init_LCD();
  36.     // Hellow World message
  37.     home_clr();
  38.     puts_lcd(pText1,sizeof(mytext1)-1);
  39.     line_2();
  40.     puts_lcd(pText2,sizeof(mytext2)-1);
  41.     // Infinite Loop
  42.     while(1){};
  43. }

Código: C#
  1. /**********************************************************************
  2. * © 2006 Microchip Technology Inc.
  3. *
  4. * FileName:        lcd.c
  5. * Dependencies:    p33FJ256GP710.h
  6. *                  lcd.h
  7. *                  delay.h
  8. * Processor:       dsPIC33F
  9. * Compiler:        MPLAB® C30 v2.01 or higher
  10. *
  11. * SOFTWARE LICENSE AGREEMENT:
  12. * Microchip Technology Inc. (“Microchip”) licenses this software to you
  13. * solely for use with Microchip dsPIC® digital signal controller
  14. * products. The software is owned by Microchip and is protected under
  15. * applicable copyright laws.  All rights reserved.
  16. *
  17. * SOFTWARE IS PROVIDED “AS IS.”  MICROCHIP EXPRESSLY DISCLAIMS ANY
  18. * WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  20. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
  21. * BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
  22. * DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
  23. * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
  24. * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
  25. * ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
  26. *
  27. * REVISION HISTORY:
  28. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. * Author            Date      Comments on this revision
  30. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. * Richard Fischer   07/14/05  Explorer 16 board LCD support
  32. * Priyabrata Sinha  01/27/06  Ported to non-prototype devices
  33. *
  34. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. *
  36. * ADDITIONAL NOTES:
  37. *
  38. **********************************************************************/
  39.  
  40. #include "p33FJ256GP710.h"
  41. #include "lcd.h"
  42. #include "delay.h"
  43.        
  44.                
  45. /*
  46.    For Explorer 16 board, here are the data and control signal definitions
  47.    RS -> RB15
  48.    E  -> RD4
  49.    RW -> RD5
  50.    DATA -> RE0 - RE7  
  51. */
  52.  
  53. // Control signal data pins
  54. #define  RW  LATDbits.LATD5       // LCD R/W signal
  55. #define  RS  LATBbits.LATB15      // LCD RS signal
  56. #define  E   LATDbits.LATD4       // LCD E signal
  57. //#define  E   LATFbits.LATF1       // LCD E signal
  58.  
  59. // Control signal pin direction
  60. #define  RW_TRIS        TRISDbits.TRISD5
  61. #define  RS_TRIS        TRISBbits.TRISB15
  62. #define  E_TRIS         TRISDbits.TRISD4
  63. //#define  E_TRIS               TRISFbits.TRISF1
  64.  
  65. // Data signals and pin direction
  66. #define  DATA      LATE           // Port for LCD data
  67. #define  DATAPORT  PORTE
  68. #define  TRISDATA  TRISE          // I/O setup for data Port
  69.  
  70.  
  71.  
  72. /****************************************************************************/
  73. /*****  LCD SUBROUTINE  *****/
  74.  
  75. void Init_LCD( void )             // initialize LCD display
  76. {
  77.         // 15mS delay after Vdd reaches nnVdc before proceeding with LCD initialization
  78.         // not always required and is based on system Vdd rise rate
  79.         Delay(Delay_15mS_Cnt);                  // 15ms delay
  80.                        
  81.         /* set initial states for the data and control pins */
  82.         LATE &= 0xFF00;
  83.     RW = 0;                       // R/W state set low
  84.         RS = 0;                       // RS state set low
  85.         E = 0;                        // E state set low
  86.  
  87.         /* set data and control pins to outputs */
  88.         TRISE &= 0xFF00;
  89.         RW_TRIS = 0;                  // RW pin set as output
  90.         RS_TRIS = 0;                  // RS pin set as output
  91.         E_TRIS = 0;                   // E pin set as output
  92.  
  93.         /* 1st LCD initialization sequence */
  94.         DATA &= 0xFF00;
  95.     DATA |= 0x0038;
  96.     E = 1;     
  97.     Nop();
  98.     Nop();
  99.     Nop();
  100.     E = 0;                        // toggle E signal
  101.         Delay(Delay_5mS_Cnt);         // 5ms delay
  102.      
  103.         /* 2nd LCD initialization sequence */
  104.         DATA &= 0xFF00;
  105.     DATA |= 0x0038;
  106.     E = 1;     
  107.     Nop();
  108.     Nop();
  109.     Nop();     
  110.     E = 0;                        // toggle E signal
  111.     Delay_Us( Delay200uS_count ); // 200uS delay
  112.  
  113.         /* 3rd LCD initialization sequence */
  114.         DATA &= 0xFF00;
  115.     DATA |= 0x0038;
  116.     E = 1;             
  117.     Nop();
  118.     Nop();
  119.     Nop();     
  120.     E = 0;                        // toggle E signal
  121.     Delay_Us( Delay200uS_count ); // 200uS delay
  122.  
  123.     lcd_cmd( 0x38 );              // function set
  124.     lcd_cmd( 0x0C );              // Display on/off control, cursor blink off (0x0C)
  125.     lcd_cmd( 0x06 );                      // entry mode set (0x06)
  126. }
  127.  
  128.  
  129. void lcd_cmd( char cmd )          // subroutiune for lcd commands
  130. {
  131. //      TRISD &= 0xFF00;              // ensure RD0 - RD7 are outputs
  132.         DATA &= 0xFF00;               // prepare RD0 - RD7
  133.     DATA |= cmd;                  // command byte to lcd
  134.         RW = 0;                       // ensure RW is 0
  135.     RS = 0;
  136.     E = 1;                        // toggle E line
  137.     Nop();
  138.     Nop();
  139.     Nop();
  140.     E = 0;
  141.         Delay(Delay_5mS_Cnt);         // 5ms delay
  142. }
  143.  
  144.  
  145. void lcd_data( char data )        // subroutine for lcd data
  146. {
  147. //      TRISD &= 0xFF00;              // ensure RD0 - RD7 are outputs
  148.         RW = 0;                                  // ensure RW is 0
  149.     RS = 1;                       // assert register select to 1
  150.         DATA &= 0xFF00;               // prepare RD0 - RD7
  151.     DATA |= data;                 // data byte to lcd
  152.     E = 1;                             
  153.         Nop();
  154.     Nop();
  155.     Nop();
  156.     E = 0;                       // toggle E signal
  157.     RS = 0;                      // negate register select to 0
  158.     Delay_Us( Delay200uS_count ); // 200uS delay
  159.     Delay_Us( Delay200uS_count ); // 200uS delay
  160. }
  161.  
  162.  
  163. void puts_lcd( unsigned char *data, unsigned int count )
  164. {
  165.         while ( count )
  166.         {
  167.                 lcd_data( *data++ );
  168.                 count --;
  169.         }      
  170. }

Código: C#
  1. /**********************************************************************
  2. * © 2006 Microchip Technology Inc.
  3. *
  4. * FileName:        lcd.h
  5. * Dependencies:    none
  6. * Processor:       dsPIC33F
  7. * Compiler:        MPLAB® C30 v2.01 or higher
  8. *
  9. * SOFTWARE LICENSE AGREEMENT:
  10. * Microchip Technology Inc. (“Microchip”) licenses this software to you
  11. * solely for use with Microchip dsPIC® digital signal controller
  12. * products. The software is owned by Microchip and is protected under
  13. * applicable copyright laws.  All rights reserved.
  14. *
  15. * SOFTWARE IS PROVIDED “AS IS.”  MICROCHIP EXPRESSLY DISCLAIMS ANY
  16. * WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  18. * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
  19. * BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
  20. * DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
  21. * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
  22. * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
  23. * ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
  24. *
  25. * REVISION HISTORY:
  26. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. * Author            Date      Comments on this revision
  28. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. * Richard Fischer   07/14/05  Explorer 16 board LCD function support
  30. * Priyabrata Sinha  01/27/06  Ported to non-prototype devices
  31. *
  32. *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. *
  34. * ADDITIONAL NOTES:
  35. *
  36. **********************************************************************/
  37.  
  38.  
  39. /****** LCD FUNCTION PROTOYPES ******/
  40.  
  41. void Init_LCD( void );          // initialize display          
  42. void lcd_cmd( char cmd );       // write command to lcd
  43. void lcd_data( char data );     // write data to lcd
  44. void puts_lcd ( unsigned char *data, unsigned int count );
  45.  
  46. /*****  LCD COMMAND FUCNTION PROTOTYPES  *****/
  47. #define cursor_right()  lcd_cmd( 0x14 )
  48. #define cursor_left()   lcd_cmd( 0x10 )
  49. #define display_shift() lcd_cmd( 0x1C )
  50. #define home_clr()      lcd_cmd( 0x01 )
  51. #define home_it()       lcd_cmd( 0x02 )
  52. #define line_2()        lcd_cmd( 0xC0 ) // (0xC0)

« Última modificación: 18 de Agosto de 2009, 06:20:25 por RedPic »
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado AKENAFAB

  • Colaborador
  • DsPIC30
  • *****
  • Mensajes: 3227
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #38 en: 30 de Diciembre de 2007, 20:09:14 »


Vaya  :shock: tremenda tarjetota, me he quedado boquiabierto.

Envidia de la buena   :mrgreen:

Sigo este hilo que me interesa entrarle a los dspic, solo que no ando muy bien con el CCS , no he practicado de lleno.

Saludos.

 Atentamente
   Akenafab

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #39 en: 01 de Enero de 2008, 14:36:04 »
Y como consecuencia lógica e irrefrenable he montado una combinación de dos de los ejemplos anteriores: La USART y el LCD. Este ejemplo "oye" la USART y lo que recibe lo coloca en el PORTA, lo devuelve por la misma USART como eco y lo coloca en el LCD en la segunda línea a partir del carácter prompt ">". Si se completa totalmente esa segunda línea del LCD la limpia y comienza de nuevo desde el segundo carácter de la segunda linea del LCD.  :mrgreen:





Código: C#
  1. /**********************************************************************
  2. * © 2008 PicManía By RedRaven
  3. *        http://picmania.garcia-cuervo.net
  4. *
  5. * FileName:        main_LCD_USART.c
  6. * Dependencies:    p33FJ256GP710.h
  7. * Processor:       dsPIC33F
  8. * Compiler:        MPLAB® C30 v2.01 or higher
  9. *
  10. * When recive USART present in LCD
  11. *
  12. * C30 Optimization Level: -O1
  13. *
  14. **********************************************************************/
  15.  
  16. #include "p33FJ256GP710.h"
  17. #include "lcd.h"
  18.  
  19. _FOSCSEL(FNOSC_FRC);
  20. _FOSC(FCKSM_CSECMD & OSCIOFNC_OFF  & POSCMD_NONE);
  21.  
  22. _FWDT(FWDTEN_OFF);
  23.  
  24. unsigned int  flag_RECUSART;
  25. unsigned char CHAR_RECUSART;
  26.  
  27. void __attribute__ ((interrupt, no_auto_psv)) _U2RXInterrupt(void){
  28.        
  29.         CHAR_RECUSART = U2RXREG;
  30.         flag_RECUSART =1;
  31.         IFS1bits.U2RXIF = 0;
  32. }
  33. void __attribute__ ((interrupt, no_auto_psv)) _U2TXInterrupt(void){
  34.         IFS1bits.U2TXIF = 0;
  35. }
  36.  
  37. void InitClock() {
  38.         PLLFBD                          = 38;   // M  = 40
  39.         CLKDIVbits.PLLPOST      = 0;    // N1 =  2
  40.         CLKDIVbits.PLLPRE       = 0;    // N2 =  2
  41.         OSCTUN                          = 0;
  42.         RCONbits.SWDTEN         = 0;
  43.         // Clock switch to incorporate PLL
  44.         __builtin_write_OSCCONH(0x01);
  45.         __builtin_write_OSCCONL(0x01);
  46.         while(OSCCONbits.LOCK != 1) {};
  47. }
  48.  
  49. void InitUART2() {
  50.         // This is an EXAMPLE, so brutal typing goes into explaining all bit sets
  51.         // The HPC16 board has a DB9 connector wired to UART2, so we will
  52.         // be configuring this port only
  53.         // configure U2MODE
  54.         U2MODEbits.UARTEN = 0;  // Bit15 TX, RX DISABLED, ENABLE at end of func
  55.         //U2MODEbits.notimplemented;    // Bit14
  56.         U2MODEbits.USIDL  = 0;  // Bit13 Continue in Idle
  57.         U2MODEbits.IREN   = 0;  // Bit12 No IR translation
  58.         U2MODEbits.RTSMD  = 0;  // Bit11 Simplex Mode
  59.         //U2MODEbits.notimplemented;    // Bit10
  60.         U2MODEbits.UEN    = 0;  // Bits8,9 TX,RX enabled, CTS,RTS not
  61.         U2MODEbits.WAKE   = 0;  // Bit7 No Wake up (since we don't sleep here)
  62.         U2MODEbits.LPBACK = 0;  // Bit6 No Loop Back
  63.         U2MODEbits.ABAUD  = 0;  // Bit5 No Autobaud (would require sending '55')
  64.         U2MODEbits.URXINV = 0;  // Bit4 IdleState = 1  (for dsPIC)
  65.         U2MODEbits.BRGH   = 0;  // Bit3 16 clocks per bit period
  66.         U2MODEbits.PDSEL  = 0;  // Bits1,2 8bit, No Parity
  67.         U2MODEbits.STSEL  = 0;  // Bit0 One Stop Bit
  68.         // Load a value into Baud Rate Generator.  Example is for 9600.
  69.         // See section 19.3.1 of datasheet.
  70.         //  U2BRG = (Fcy/(16*BaudRate))-1
  71.         //  U2BRG = (37M/(16*9600))-1
  72.         //  U2BRG = 240
  73.         U2BRG = 240;            // 40Mhz osc, 9600 Baud
  74.         // Load all values in for U1STA SFR
  75.         U2STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
  76.         U2STAbits.UTXINV   = 0; //Bit14 N/A, IRDA config
  77.         U2STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
  78.         //U2STAbits.notimplemented = 0; //Bit12
  79.         U2STAbits.UTXBRK   = 0; //Bit11 Disabled
  80.         U2STAbits.UTXEN    = 0; //Bit10 TX pins controlled by periph
  81.         U2STAbits.UTXBF    = 0; //Bit9 *Read Only Bit*
  82.         U2STAbits.TRMT     = 0; //Bit8 *Read Only bit*
  83.         U2STAbits.URXISEL  = 0; //Bits6,7 Int. on character recieved
  84.         U2STAbits.ADDEN    = 0; //Bit5 Address Detect Disabled
  85.         U2STAbits.RIDLE    = 0; //Bit4 *Read Only Bit*
  86.         U2STAbits.PERR     = 0; //Bit3 *Read Only Bit*
  87.         U2STAbits.FERR     = 0; //Bit2 *Read Only Bit*
  88.         U2STAbits.OERR     = 0; //Bit1 *Read Only Bit*
  89.         U2STAbits.URXDA    = 0; //Bit0 *Read Only Bit*
  90.         IPC7 = 0x4400;                  //Mid Range Interrupt Priority level, no urgent reason
  91.         IFS1bits.U2TXIF    = 0; //Clear the Transmit Interrupt Flag
  92.         IEC1bits.U2TXIE    = 1; //Enable Transmit Interrupts
  93.         IFS1bits.U2RXIF    = 0; //Clear the Recieve Interrupt Flag
  94.         IEC1bits.U2RXIE    = 1; //Enable Recieve Interrupts
  95.         U2MODEbits.UARTEN  = 1; //And turn the peripheral on
  96.         U2STAbits.UTXEN = 1;
  97. }
  98.  
  99. void putUART2( char c){
  100.         while ( U2STAbits.UTXBF); // wait while Tx buffer full
  101.         U2TXREG = c;
  102. }
  103.  
  104. void putsUART2( char *s){
  105.         unsigned int i=0;
  106.         while(s[i])             // loop until *s == ‘\0’, end of string
  107.                 putUART2(s[i++]);       // send the character and point to the next one
  108. }
  109.  
  110. int main(void){
  111.  
  112.         char mytext1[] = "dsPIC33F-PCtoLCD";
  113.         char mytext2[] = ">               ";
  114.     char *pText1=&mytext1[0];
  115.     char *pText2=&mytext2[0];
  116.         unsigned int nCHARS=0;
  117.  
  118.        
  119.         TRISA = 0x0000; // All to output
  120.         InitClock();    // This is the PLL settings
  121.         InitUART2();    // Initialize UART2 for 9600,8,N,1 TX/RX
  122.         Init_LCD();             // Initialize LCD
  123.         // Send to serial
  124.         putsUART2(mytext1);
  125.         putsUART2("\r\n");
  126.         // Hellow World message
  127.         home_clr();
  128.         puts_lcd(pText1,sizeof(mytext1)-1);
  129.         line_2();
  130.         puts_lcd(pText2,sizeof(mytext2)-1);
  131.         line_2();
  132.         cursor_right();
  133.     // Infinite Loop
  134.         flag_RECUSART = 0;
  135.     while(1){
  136.                 if(flag_RECUSART==1){
  137.                         flag_RECUSART=0;
  138.                         LATA = CHAR_RECUSART;     // Lo que recibo vía UART2 lo pongo en el PORTA ...
  139.                         putUART2(CHAR_RECUSART);  // ... lo devuelvo como eco ...
  140.                         lcd_data(CHAR_RECUSART);  // ... y lo pongo en el LCD
  141.                         if(++nCHARS==15){
  142.                                 line_2();
  143.                                 puts_lcd(pText2,sizeof(mytext2)-1);
  144.                                 line_2();
  145.                                 cursor_right();
  146.                                 nCHARS=0;
  147.                         }
  148.                 }
  149.         };
  150. }
« Última modificación: 18 de Agosto de 2009, 06:22:04 por RedPic »
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado Renatox_

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 541
    • máquinas cnc
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #40 en: 01 de Enero de 2008, 16:29:22 »
El CCS y el C30 tienen algo en comun que es la forma de configurar los bits, eso es bueno.

como esto:

U2MODEbits.UEN    = 0;   // Bits8,9 TX,RX enabled, CTS,RTS not

suerte con los dspic, estás aprendiendo rápido.

un saludo;
control de movimiento

Desconectado RedPic

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 5544
    • Picmania by Redraven
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #41 en: 01 de Enero de 2008, 16:49:06 »
Si, menos dá una piedra y algo es algo. Pero la verdad es que es mucho mas dificil ya que le faltan las funciones de alto nivel que tiene el CCS C. Y se juntan el hambre con las ganas de comer, los dsPIC tienen muchísimos mas registros de configuración, y por ende muchos mas bits, y al no tener las funciones de alto nivel hay que configurar docenas de bits para hacer que algo funcione.

El ejemplo mas espectacular que he visto hasta ahora es el de la USART. En CCS C se soluciona con una línea, en el C30 hay que escribir un kbyte de texto con la configuración:

CCS C

Código: C#
  1. #use rs232(baud=115200, xmit=RC6, rcv=RC7, ERRORS)

C30

Código: C#
  1. void InitUART2() {
  2.  
  3.         U2MODEbits.UARTEN = 0;  // Bit15 TX, RX DISABLED, ENABLE at end of func
  4.         //U2MODEbits.notimplemented;    // Bit14
  5.         U2MODEbits.USIDL  = 0;  // Bit13 Continue in Idle
  6.         U2MODEbits.IREN   = 0;  // Bit12 No IR translation
  7.         U2MODEbits.RTSMD  = 0;  // Bit11 Simplex Mode
  8.         //U2MODEbits.notimplemented;    // Bit10
  9.         U2MODEbits.UEN    = 0;  // Bits8,9 TX,RX enabled, CTS,RTS not
  10.         U2MODEbits.WAKE   = 0;  // Bit7 No Wake up (since we don't sleep here)
  11.         U2MODEbits.LPBACK = 0;  // Bit6 No Loop Back
  12.         U2MODEbits.ABAUD  = 0;  // Bit5 No Autobaud (would require sending '55')
  13.         U2MODEbits.URXINV = 0;  // Bit4 IdleState = 1  (for dsPIC)
  14.         U2MODEbits.BRGH   = 0;  // Bit3 16 clocks per bit period
  15.         U2MODEbits.PDSEL  = 0;  // Bits1,2 8bit, No Parity
  16.         U2MODEbits.STSEL  = 0;  // Bit0 One Stop Bit
  17.         // Load a value into Baud Rate Generator.  Example is for 9600.
  18.         U2BRG = 240;            // 40Mhz osc, 9600 Baud
  19.         // Load all values in for U1STA SFR
  20.         U2STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
  21.         U2STAbits.UTXINV   = 0; //Bit14 N/A, IRDA config
  22.         U2STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
  23.         //U2STAbits.notimplemented = 0; //Bit12
  24.         U2STAbits.UTXBRK   = 0; //Bit11 Disabled
  25.         U2STAbits.UTXEN    = 0; //Bit10 TX pins controlled by periph
  26.         U2STAbits.UTXBF    = 0; //Bit9 *Read Only Bit*
  27.         U2STAbits.TRMT     = 0; //Bit8 *Read Only bit*
  28.         U2STAbits.URXISEL  = 0; //Bits6,7 Int. on character recieved
  29.         U2STAbits.ADDEN    = 0; //Bit5 Address Detect Disabled
  30.         U2STAbits.RIDLE    = 0; //Bit4 *Read Only Bit*
  31.         U2STAbits.PERR     = 0; //Bit3 *Read Only Bit*
  32.         U2STAbits.FERR     = 0; //Bit2 *Read Only Bit*
  33.         U2STAbits.OERR     = 0; //Bit1 *Read Only Bit*
  34.         U2STAbits.URXDA    = 0; //Bit0 *Read Only Bit*
  35.         IPC7 = 0x4400;                  //Mid Range Interrupt Priority level, no urgent reason
  36.         IFS1bits.U2TXIF    = 0; //Clear the Transmit Interrupt Flag
  37.         IEC1bits.U2TXIE    = 1; //Enable Transmit Interrupts
  38.         IFS1bits.U2RXIF    = 0; //Clear the Recieve Interrupt Flag
  39.         IEC1bits.U2RXIE    = 1; //Enable Recieve Interrupts
  40.         U2MODEbits.UARTEN  = 1; //And turn the peripheral on
  41.         U2STAbits.UTXEN = 1;
  42. }
Contra la estupidez los propios dioses luchan en vano. Schiller
Mi Güeb : Picmania

Desconectado Renatox_

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 541
    • máquinas cnc
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #42 en: 01 de Enero de 2008, 19:10:31 »
Hola, asi es al principio difícil. una ves que te familiarices con el hardware prederirás configurarlo bit a bit a hacerlo con las funciones del CCS, pon tus archivos config() de los módulos en un archivo C aparte para que no se te llene el archivo main.c.

control de movimiento

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7912
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #43 en: 01 de Enero de 2008, 21:08:37 »
No has probado con CCS PCD ??? :mrgreen:
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: Explorer 16 y QVGA: Primeros Pasos
« Respuesta #44 en: 02 de Enero de 2008, 05:32:28 »
Don Diego, aquí está el PDF que te comenté en la cafetería.

No te vas a librar de estudiar las datasheets para configurar los periféricos, pero al menos tu código quedará más inteligible si utilizas las librerías que incorpora el C30. Aquí vienen todas explicadas, incluso las de funciones avanzadas del módulo dsp.

http://ww1.microchip.com/downloads/en/DeviceDoc/16Bit_Language_Tool_Libraries_51456d.pdf