TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: camigod en 26 de Diciembre de 2009, 21:56:58

Título: LCD NOKIA COLOR CON 18F4550
Publicado por: camigod en 26 de Diciembre de 2009, 21:56:58
Hola a todos, acabo de comprar la LCD de un nokia 6100

http://www.sparkfun.com/commerce/product_info.php?products_id=8600

Estoy trabajando con un PIC 18F4550 y con el compilador CCS, en la misma pagina de SPARKFUN dan algunos ejemplos de la forma de uso y uno de los mas simples es el de Marcus Russell que adjunto en este mensaje.

En dicho ejemplo manejan un PIC16LF872 y configuran el modulo SPI... Pues, yo estoy tratando de hacer lo mismo pero utilizando el PIC 18F4550, pero al parecer y por lo que he leido en varios temas de este foro, la configuracion del SPI en CCS para este PIC no funciona bien... :(

Alguien podria decirme como puedo solucionar esto? o decirme de que forma puedo hacer funcionar la LCD con este compilador y este PIC?

Muchas Gracias de ante mano.
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: camigod en 28 de Diciembre de 2009, 20:18:38
No hay respuestas? :(

En fin, mañana pienso comprar otro PIC, tal vez el 18F2520 o el 16F872 e intentare de nuevo...

De todas formas quisiera saber si alguien conoce como manejar SPI en CCS para un 18F4550... gracias
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: Nocturno en 29 de Diciembre de 2009, 03:14:02
Pega por aquí tu programa por si vemos algo raro.
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: MLO__ en 29 de Diciembre de 2009, 13:50:02
Hola.

Código: C#
  1. //// Marcus Russell
  2. //// Russell Evolutions Inc.
  3. //// Nokia 6100 LCD with Epson S1D15G10 Controller
  4. ////  sample initialization program for PIC16LF872 in CCS C  3-14-07
  5. ////
  6. //// Based on Spark Fun Electronics Code by Owen Osborn 1-22-05
  7. ////   with thanks to David Carne of SFE for DISCTL help
  8. ////   and user 'Ttelmah' from CCS C forum for SSPEN bit idea for 9-bit hardware SPI
  9. ////
  10. //// You are free to use this code for any purpose.
  11. ////
  12. ////
  13. //// START OF HEADER FILE ////
  14.  
  15. #include <16F872.h>
  16. #device adc=8
  17.  
  18. #FUSES NOWDT                    //No Watch Dog Timer
  19. #FUSES XT                       //Crystal Osc (<= 4mhz)
  20. #FUSES PUT                      //Power Up Timer
  21. #FUSES NOPROTECT                //Code not protected from reading
  22. #FUSES NODEBUG                  //No Debug mode for ICD
  23. #FUSES NOBROWNOUT               //Don't Reset when brownout detected
  24. #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  25. #FUSES NOCPD                    //No EE protection
  26. #FUSES NOWRT                    //Program memory not write protected
  27.  
  28. #use delay(clock=4000000)
  29. #define LCD_RESET   PIN_C0
  30. #define LCD_CS   PIN_C1
  31. #define SPI_CLK   PIN_C3
  32. #define SPI_DI   PIN_C4 //unused
  33. #define SPI_DO   PIN_C5
  34.  
  35. #bit SSPEN = 0x14.5   // bit to turn on/off hardware SPI
  36.  
  37. // Epson S1D15G10 Command Set
  38.  
  39. #define DISON       0xaf
  40. #define DISOFF      0xae
  41. #define DISNOR      0xa6
  42. #define DISINV      0xa7
  43. #define SLPIN       0x95
  44. #define SLPOUT      0x94
  45. #define COMSCN      0xbb
  46. #define DISCTL      0xca
  47. #define PASET       0x75
  48. #define CASET       0x15
  49. #define DATCTL      0xbc
  50. #define RGBSET8     0xce
  51. #define RAMWR       0x5c
  52. #define RAMRD       0x5d
  53. #define PTLIN       0xa8
  54. #define PTLOUT      0xa9
  55. #define RMWIN       0xe0
  56. #define RMWOUT      0xee
  57. #define ASCSET      0xaa
  58. #define SCSTART     0xab
  59. #define OSCON       0xd1
  60. #define OSCOFF      0xd2
  61. #define PWRCTR      0x20
  62. #define VOLCTR      0x81
  63. #define VOLUP       0xd6
  64. #define VOLDOWN     0xd7
  65. #define TMPGRD      0x82
  66. #define EPCTIN      0xcd
  67. #define EPCOUT      0xcc
  68. #define EPMWR       0xfc
  69. #define EPMRD       0xfd
  70. #define EPSRRD1     0x7c
  71. #define EPSRRD2     0x7d
  72. #define NOP         0x25
  73.  
  74. #define ENDPAGE     132
  75. #define ENDCOL      130
  76.  
  77.  
  78. ////  START OF MAIN .C SOURCE FILE ////
  79.  
  80. //#include "<path to .h file cut from above>"
  81. #use fast_io(C)
  82.  
  83. void pset(unsigned char color, unsigned char x, unsigned char y);
  84. void spi_command(int);
  85. void spi_data(int);
  86.  
  87. void main()
  88. {
  89.  
  90.    int16 i;
  91.  
  92.    setup_adc_ports(NO_ANALOGS);
  93.    setup_adc(ADC_OFF);
  94.    setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
  95.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  96.    setup_timer_1(T1_DISABLED);
  97.    setup_timer_2(T2_DISABLED, 0, 1);
  98.    set_tris_c(0x00);   // all outputs, can change to mask only hardware SPI bits if needed
  99.  
  100.    // reset display
  101.  
  102.    output_low (SPI_CLK);
  103.    output_low (SPI_DO);
  104.    output_high (LCD_CS);
  105.    output_low (LCD_RESET);
  106.    delay_ms(100);
  107.    output_high (LCD_RESET);
  108.  
  109.    //init'd, now drop CS to send commands/data and raise when finished
  110.  
  111.     spi_command(DISCTL);  // display control
  112.     spi_data(0x0C);      // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
  113.     spi_data(0x20);      // 32 = (128/4)-1 (round up) number of display lines for scanning
  114.     spi_data(0x0C);      // 12 = 1100 - number of lines to be inversely highlighted
  115.     spi_data(0x00);
  116.  
  117.     spi_command(COMSCN);  // common scanning direction
  118.     spi_data(0x01);
  119.     // 0 0 0 =   1 -> 80   81 -> 160
  120.     // 0 0 1 =   1 -> 80   81 <- 160
  121.     // 0 1 0 =   1 <- 80   81 -> 160
  122.     // 0 1 1 =   1 <- 80   81 <- 160
  123.  
  124.     spi_command(OSCON);  // internal oscialltor ON
  125.  
  126.     spi_command(SLPOUT);  // sleep out
  127.  
  128.     spi_command(VOLCTR);  // electronic volume, this is the contrast/brightness
  129.     spi_data(0x23);   // volume (contrast) setting - fine tuning
  130.     spi_data(0x03);   // internal resistor ratio - coarse adjustment
  131.  
  132.     spi_command(PWRCTR);  // power ctrl
  133.     spi_data(0x0f);      //everything on, no external reference resistors
  134.     delay_ms(100);
  135.  
  136.     spi_command(DISINV);  // invert display mode
  137.  
  138.     spi_command(DATCTL);  // data control
  139.     spi_data(0x00);   // normal display of page/column address, page scan direction
  140.     spi_data(0x00);   // normal RGB arrangement
  141.     spi_data(0x01);   // 8-bit grayscale
  142.  
  143.     spi_command(RGBSET8);   // setup 8-bit color lookup table  [RRRGGGBB]
  144.     //RED
  145.     spi_data(0);
  146.     spi_data(2);
  147.     spi_data(4);
  148.     spi_data(6);
  149.     spi_data(8);
  150.     spi_data(10);
  151.     spi_data(12);
  152.     spi_data(15);
  153.     // GREEN
  154.     spi_data(0);
  155.     spi_data(2);
  156.     spi_data(4);
  157.     spi_data(6);
  158.     spi_data(8);
  159.     spi_data(10);
  160.     spi_data(12);
  161.     spi_data(15);
  162.     //BLUE
  163.     spi_data(0);
  164.     spi_data(4);
  165.     spi_data(9);
  166.     spi_data(15);
  167.  
  168.     spi_command(NOP);  // nop
  169.  
  170.   pset(0b11100000, 0, 0); // red pixel top left (also sets start of bulk write, see pset routine)
  171.  
  172.   for (i = 1; i <= 16900; i++) {  // 130x130 = 16900
  173.       spi_data(0b11100000);   // fill screen red
  174.   }
  175.  
  176.   spi_command(DISON);   // display on
  177.  
  178.   while (1) {  // main program loop.  just blinks A0 to show chip is running
  179.       output_toggle(PIN_A0);
  180.       delay_ms(500);
  181.    }
  182. }
  183.  
  184. void pset(unsigned char color, unsigned char x, unsigned char y){
  185. //  sets the starting page(row) and column (x & y) coordinates in ram,
  186. //  then writes the colour to display memory.  The ending x & y are left
  187. //  maxed out so one can continue sending colour data bytes to the 'open'
  188. //  RAMWR command to fill further memory.  issuing any other command
  189. //  finishes RAMWR.
  190.  
  191.   x += 2;                  // for some reason starts at 2
  192.  
  193.   spi_command(PASET);   // page start/end ram
  194.   spi_data(x);
  195.   spi_data(ENDPAGE);
  196.  
  197.   spi_command(CASET);   // column start/end ram
  198.   spi_data(y);
  199.   spi_data(ENDCOL);
  200.  
  201.   spi_command(RAMWR);    // write
  202.   spi_data(color);
  203. }
  204.  
  205. void spi_command(int dat){
  206.  
  207.    output_low(LCD_CS);      // enable chip
  208.    SSPEN = 0;               // shut off hardware SPI allowing direct access to SPI in/out pins
  209.    output_low (SPI_DO);     // output low on data out (9th bit low = command)
  210.    output_high (SPI_CLK);
  211.    delay_cycles(1);         // send clock pulse
  212.    output_low (SPI_CLK);
  213.    SSPEN=1;                 // turn hardware SPI back on
  214.    spi_write(dat);          // make PIC do the work for the command byte
  215.    output_high(LCD_CS);     // disable
  216.  
  217. }
  218.  
  219. void spi_data(int dat){
  220.  
  221.    output_low(LCD_CS);      // enable chip
  222.    SSPEN = 0;               // turn off hardware SPI allowing us direct access to SPI in/out pins
  223.    output_high (SPI_DO);    // output high on data out (9th bit high = data)
  224.    output_high (SPI_CLK);
  225.    delay_cycles(1);         // send clock pulse
  226.    output_low (SPI_CLK);
  227.    SSPEN=1;                 // turn hardware SPI back on
  228.    spi_write(dat);          // make PIC do the work for the data byte
  229.    output_high(LCD_CS);     // disable
  230. }

No he usado nunca el SPI con ese micro, algo recuerdo de que alguien si lo habia usado y le fue bien. De todas maneras, analiza el envio desde proteus a ver que sucede.

Saludos
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: camigod en 29 de Diciembre de 2009, 16:08:19
Hola, gracias por las respuestas,

El codigo que estoy usando es precisamente el que posteo MLO_ solo que modifique algunas cosas para usarlo con el 18F4550.

Lo pongo a continuacion con las modificaciones hechas:

Código: [Seleccionar]
#include <18f4550.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#define LCD_RESET   PIN_C0
#define LCD_CS   PIN_C1
[b]#define SPI_CLK   PIN_B1      //CLK PARA EL 18F4550[/b]
#define SPI_DI   PIN_C4 //unused
[b]#define SPI_DO   PIN_C7      //DO PARA EL 18F4550[/b]

#[b]bit SSPEN = 0xFC6.5   //DIRECCION PARA EL 18F4550[/b]

// Epson S1D15G10 Command Set

#define DISON       0xaf
#define DISOFF      0xae
#define DISNOR      0xa6
#define DISINV      0xa7
#define SLPIN       0x95
#define SLPOUT      0x94
#define COMSCN      0xbb
#define DISCTL      0xca
#define PASET       0x75
#define CASET       0x15
#define DATCTL      0xbc
#define RGBSET8     0xce
#define RAMWR       0x5c
#define RAMRD       0x5d
#define PTLIN       0xa8
#define PTLOUT      0xa9
#define RMWIN       0xe0
#define RMWOUT      0xee
#define ASCSET      0xaa
#define SCSTART     0xab
#define OSCON       0xd1
#define OSCOFF      0xd2
#define PWRCTR      0x20
#define VOLCTR      0x81
#define VOLUP       0xd6
#define VOLDOWN     0xd7
#define TMPGRD      0x82
#define EPCTIN      0xcd
#define EPCOUT      0xcc
#define EPMWR       0xfc
#define EPMRD       0xfd
#define EPSRRD1     0x7c
#define EPSRRD2     0x7d
#define NOP         0x25

#define ENDPAGE     132
#define ENDCOL      130

#use fast_io(C)
#use fast_io(B)
#use standard_io(A)


void spi_command(int dat){

   output_low(LCD_CS);      // enable chip
   SSPEN = 0;               // shut off hardware SPI allowing direct access to SPI in/out pins
   output_low (SPI_DO);     // output low on data out (9th bit low = command)
   output_high (SPI_CLK);
   delay_cycles(1);         // send clock pulse
   output_low (SPI_CLK);
   SSPEN=1;                 // turn hardware SPI back on
   spi_write(dat);          // make PIC do the work for the command byte
   output_high(LCD_CS);     // disable

}

void spi_data(int dat){

   output_low(LCD_CS);      // enable chip
   SSPEN = 0;               // turn off hardware SPI allowing us direct access to SPI in/out pins
   output_high (SPI_DO);    // output high on data out (9th bit high = data)
   output_high (SPI_CLK);
   delay_cycles(1);         // send clock pulse
   output_low (SPI_CLK);
   SSPEN=1;                 // turn hardware SPI back on
   spi_write(dat);          // make PIC do the work for the data byte
   output_high(LCD_CS);     // disable
}

void pset(unsigned char color, unsigned char x, unsigned char y){
//  sets the starting page(row) and column (x & y) coordinates in ram,
//  then writes the colour to display memory.  The ending x & y are left
//  maxed out so one can continue sending colour data bytes to the 'open'
//  RAMWR command to fill further memory.  issuing any other command
//  finishes RAMWR.

  x += 2;                  // for some reason starts at 2

  spi_command(PASET);   // page start/end ram
  spi_data(x);
  spi_data(ENDPAGE);

  spi_command(CASET);   // column start/end ram
  spi_data(y);
  spi_data(ENDCOL);

  spi_command(RAMWR);    // write
  spi_data(color);
}

void main()
{
int16 i;
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   [b]for(i=0;i<5;i++){
      output_low (PIN_A0);
      delay_ms(600);
      output_high (PIN_A0);
      delay_ms(300);
   }[/b]
   output_low (SPI_CLK);
   output_low (SPI_DO);
   output_high (LCD_CS);
   output_low (LCD_RESET);
   delay_ms(100);
   output_high (LCD_RESET);

    spi_command(DISCTL);  // display control
    spi_data(0x0C);      // 12 = 1100 - CL dividing ratio [don't divide] switching period 8H (default)
    spi_data(0x20);      // 32 = (128/4)-1 (round up) number of display lines for scanning
    spi_data(0x0C);      // 12 = 1100 - number of lines to be inversely highlighted
    spi_data(0x00);

    spi_command(COMSCN);  // common scanning direction
    spi_data(0x01);

    [b]for(i=0;i<5;i++){
      output_low (PIN_A0);
      delay_ms(600);
      output_high (PIN_A0);
      delay_ms(300);
   }[/b]
    // 0 0 0 =   1 -> 80   81 -> 160
    // 0 0 1 =   1 -> 80   81 <- 160
    // 0 1 0 =   1 <- 80   81 -> 160
    // 0 1 1 =   1 <- 80   81 <- 160

    spi_command(OSCON);  // internal oscialltor ON

    spi_command(SLPOUT);  // sleep out

    spi_command(VOLCTR);  // electronic volume, this is the contrast/brightness
    spi_data(0x23);   // volume (contrast) setting - fine tuning
    spi_data(0x03);   // internal resistor ratio - coarse adjustment

    spi_command(PWRCTR);  // power ctrl
    spi_data(0x0f);      //everything on, no external reference resistors
    delay_ms(100);

    spi_command(DISINV);  // invert display mode

    spi_command(DATCTL);  // data control
    spi_data(0x00);   // normal display of page/column address, page scan direction
    spi_data(0x00);   // normal RGB arrangement
    spi_data(0x01);   // 8-bit grayscale

    spi_command(RGBSET8);   // setup 8-bit color lookup table  [RRRGGGBB]
    //RED
    spi_data(0);
    spi_data(2);
    spi_data(4);
    spi_data(6);
    spi_data(8);
    spi_data(10);
    spi_data(12);
    spi_data(15);
    // GREEN
    spi_data(0);
    spi_data(2);
    spi_data(4);
    spi_data(6);
    spi_data(8);
    spi_data(10);
    spi_data(12);
    spi_data(15);
    //BLUE
    spi_data(0);
    spi_data(4);
    spi_data(9);
    spi_data(15);

    spi_command(NOP);  // nop

  pset(0b11100000, 0, 0); // red pixel top left (also sets start of bulk write, see pset routine)

  for (i = 1; i <= 16900; i++) {  // 130x130 = 16900
      spi_data(0b11100000);   // fill screen red
  }

  spi_command(DISON);   // display on

  while (1) {  // main program loop.  just blinks A0 to show chip is running
      output_toggle(PIN_A0);
      delay_ms(500);
   }

}

Como pueden ver, basicamente es el mismo codigo, solo modifique la direccion en memoria del SSPEN, y los pines de salida tanto del CLK como del DO. Los dos ciclos FOR en negrilla los añadi para verificar que el codigo estubiera funcionando y lo que ocurre es que el programa nunca llega al segundo ciclo :?,

Por otro lado revisando algunos ejemplos realizados con la libreria GCLCD de J1M los cuales utilizan un 18F2520, me di cuenta que añaden algunas resistencias a la salida de los pines como se muestra en la imagen que adjunto... es esto necesario??

Gracias
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: Nocturno en 29 de Diciembre de 2009, 16:31:19
Has definido funciones para utilizar el SPI por software, gestionando desde tu programa los pines de clock y datos.
Si lo haces así, no puedes utilizar el SPI por hardware:
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);

Si prefieres utilizar el SPI por hardware, cosa que es recomendable, no puedes utilizar tus funciones, sino las que proporciona CCS:
spi_write() y spi_read()
Título: Re: LCD NOKIA COLOR CON 18F4550
Publicado por: camigod en 29 de Diciembre de 2009, 17:26:28
Es decir que la estructura del codigo inicial de Marcus Russel es incorrecta??

Jejeje vale, ya teniendo una idea mas clara, probare con los ejemplos de J1M,

Muchas gracias.