CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

LCD 2*16 with 18f4620

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Knight_FlyCn



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

LCD 2*16 with 18f4620
PostPosted: Wed Jun 05, 2013 1:00 pm     Reply with quote

I finding code LCD 4bit for 18f4620. who can help me ?
_________________
Thinh
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Wed Jun 05, 2013 1:33 pm     Reply with quote

One version (LCD.C) comes with the compiler. More flexible, and generally as/more reliable, is the 'flex lcd' driver in the code forum.
Learn to use search before asking questions.
Knight_FlyCn



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

PostPosted: Thu Jun 06, 2013 12:26 pm     Reply with quote

This is my code

Code:
#include <RFD.h>
#include "string.h"
#include "stdio.h"
#include "def_18f4620.c"
#include "slave_1_tx_rx.h"
#include "LCD.C"

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)

#bit CS     = 0xF83.0
#bit RST    = 0xF83.2
#bit INT_   = 0xF81.1
#bit WAKE   = 0xF83.1

#bit CS_Direction    = 0xF95.0
#bit RST_Direction   = 0xF95.2
#bit INT_Direction   = 0xF93.1
// Enter Code Here

#define LCD_ENABLE_PIN  TRISD2                                   ////
#define LCD_RS_PIN      TRISD0                                    ////
#define LCD_RW_PIN      TRISD1                                    ////
#define LCD_DATA4       TRISD4                                    ////
#define LCD_DATA5       TRISD5                                    ////
#define LCD_DATA6       TRISD6                                    ////
#define LCD_DATA7       TRISD7                                    ////

///////////////////////////////////////////////////////////////////

INT TEMP;
INT giatri = 0;
INT DATA_SEND=2;
INT COMMAND;
SHORT SLEEP_MODE=true;

///////////////////////////////////////////////////////////////////
int i;
char value[12];
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////



void main()
{
   TRISC0 = 0;
   CS_Direction   = 0;     // Set direction to be output
   RST_Direction  = 0;     // Set direction to be output
   INT_Direction  = 1;     // Set direction to be input
   WAKE_Direction = 0;     // Set direction to be output
   
   Delay_ms(5); 
   setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4);  // Initialize SPI module
   pin_reset();                              // Activate reset from pin
   software_reset();                         // Activate software reset
   RF_reset();                               // RF reset
   set_WAKE_from_pin();                      // Set wake from pin
   set_long_address(ADDRESS_long_1); 
   set_short_address(rfd_ADDRESS_short);       // Set short address
   set_PAN_ID(PAN_ID);                     // Set PAN_ID

   init_ZIGBEE_nonbeacon();                  // Initialize ZigBee module
   nonbeacon_device();
   set_TX_power(31);                         // Set max TX power
   set_frame_format_filter(1);               // 1 all frames, 3 data frame only
   set_reception_mode(1);                    // 1 normal mode
   enable_int();
   pin_wake(); // Wake from pin
   
   //enable interrupt ext

   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_RDA);
   ext_int_edge(H_to_L);
   // gioi thieu
   
   lcd_putc(" Hello Hello");
   Printf("    Bat Dau Lai RFID 1\r\n");
////////////////////////////////////////////////////////
   
   while (1)
  {
  {
  for (i=0; i<12; i++) { //read in the 12 values
           value[i]=getc();
     }
     printf("RFID %c %c %c %c %c %c %c %c %c %c \r\n", value[1] value[2] value[3] value[4] value[5] value[6] value[7] value[8] value[9] value[10]); //display 10 unique id digits
}

  }
 
}



But don't anything happen. Where is my wrong ?
_________________
Thinh
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 12:30 pm     Reply with quote

Because things have to be defined _before_ they are used. How is LCD, meant to know about your pin definitions?....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 1:10 pm     Reply with quote

Quote:

#define LCD_ENABLE_PIN TRISD2
#define LCD_RS_PIN TRISD0
#define LCD_RW_PIN TRISD1
#define LCD_DATA4 TRISD4
#define LCD_DATA5 TRISD5
#define LCD_DATA6 TRISD6
#define LCD_DATA7 TRISD7

Why did you define the lcd pins as TRIS register settings ?
The CCS example in the lcd.c file doesn't do this.
Why did you do it ?

Here is the CCS example from lcd.c, and it shows pin numbers:
Code:

////  Example of pin access:                                             
////     #define LCD_ENABLE_PIN  PIN_E0                                   
////     #define LCD_RS_PIN      PIN_E1                                   
////     #define LCD_RW_PIN      PIN_E2                                   
////     #define LCD_DATA4       PIN_D4                                   
////     #define LCD_DATA5       PIN_D5                                   
////     #define LCD_DATA6       PIN_D6                                   
////     #define LCD_DATA7       PIN_D7   
Knight_FlyCn



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

PostPosted: Thu Jun 06, 2013 1:11 pm     Reply with quote

I repair it

Code:
#include <RFD.h>
#include "string.h"
#include "stdio.h"
#include "def_18f4620.c"
#include "slave_1_tx_rx.h"
#include "LCD.C"

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)

#bit CS     = 0xF83.0
#bit RST    = 0xF83.2
#bit INT_   = 0xF81.1
#bit WAKE   = 0xF83.1

#bit CS_Direction    = 0xF95.0
#bit RST_Direction   = 0xF95.2
#bit INT_Direction   = 0xF93.1
// Enter Code Here

#define LCD_ENABLE_PIN  TRISD2                                   ////
#define LCD_RS_PIN      TRISD0                                    ////
#define LCD_RW_PIN      TRISD1                                    ////
#define LCD_DATA4       TRISD4                                    ////
#define LCD_DATA5       TRISD5                                    ////
#define LCD_DATA6       TRISD6                                    ////
#define LCD_DATA7       TRISD7                                    ////

///////////////////////////////////////////////////////////////////

INT TEMP;
INT giatri = 0;
INT DATA_SEND=2;
INT COMMAND;
SHORT SLEEP_MODE=true;

///////////////////////////////////////////////////////////////////
int i;
char value[12];
//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////



void main()
{
   TRISC0 = 0;
   CS_Direction   = 0;     // Set direction to be output
   RST_Direction  = 0;     // Set direction to be output
   INT_Direction  = 1;     // Set direction to be input
   WAKE_Direction = 0;     // Set direction to be output
   
   Delay_ms(5); 
   setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4);  // Initialize SPI module
   pin_reset();                              // Activate reset from pin
   software_reset();                         // Activate software reset
   RF_reset();                               // RF reset
   set_WAKE_from_pin();                      // Set wake from pin
   set_long_address(ADDRESS_long_1); 
   set_short_address(rfd_ADDRESS_short);       // Set short address
   set_PAN_ID(PAN_ID);                     // Set PAN_ID

   init_ZIGBEE_nonbeacon();                  // Initialize ZigBee module
   nonbeacon_device();
   set_TX_power(31);                         // Set max TX power
   set_frame_format_filter(1);               // 1 all frames, 3 data frame only
   set_reception_mode(1);                    // 1 normal mode
   enable_int();
   pin_wake(); // Wake from pin
   
   //enable interrupt ext

   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_RDA);
   ext_int_edge(H_to_L);
   // gioi thieu
   

  lcd_init();
   lcd_putc(" Hello Hello");
   Printf("    Bat Dau Lai RFID 1\r\n");
////////////////////////////////////////////////////////
   
   while (1)
  {
  {
  for (i=0; i<12; i++) { //read in the 12 values
           value[i]=getc();
     }
     printf("RFID %c %c %c %c %c %c %c %c %c %c \r\n", value[1] value[2] value[3] value[4] value[5] value[6] value[7] value[8] value[9] value[10]); //display 10 unique id digits
}

  }
 
}


But dont' happend. who help me ?
_________________
Thinh
Knight_FlyCn



Joined: 10 May 2013
Posts: 16
Location: Việt Nam

View user's profile Send private message AIM Address

PostPosted: Thu Jun 06, 2013 1:13 pm     Reply with quote

PCM programmer wrote:
Quote:

#define LCD_ENABLE_PIN TRISD2
#define LCD_RS_PIN TRISD0
#define LCD_RW_PIN TRISD1
#define LCD_DATA4 TRISD4
#define LCD_DATA5 TRISD5
#define LCD_DATA6 TRISD6
#define LCD_DATA7 TRISD7

Why did you define the lcd pins as TRIS register settings ?
The CCS example in the lcd.c file doesn't do this.
Why did you do it ?

Here is the CCS example from lcd.c, and it shows pin numbers:
Code:

////  Example of pin access:                                             
////     #define LCD_ENABLE_PIN  PIN_E0                                   
////     #define LCD_RS_PIN      PIN_E1                                   
////     #define LCD_RW_PIN      PIN_E2                                   
////     #define LCD_DATA4       PIN_D4                                   
////     #define LCD_DATA5       PIN_D5                                   
////     #define LCD_DATA6       PIN_D6                                   
////     #define LCD_DATA7       PIN_D7   


Because I use file "def_18f4620.c" for myselfs .

Code:
// PIC 18F4620
//////////////////////////////////////////////////////////////////////////////
// EDIT BY NGUYEN VAN THINH


#define T   0
#define F   1

#byte   TOSU      = 0xFFF
#byte   TOSH      = 0xFFE
#byte   TOSL      = 0xFFD
#byte   STKPTR    = 0xFFC
#byte   PCLATU    = 0xFFB
#byte   PCLATH    = 0xFFA
#byte   PCL       = 0xFF9
#byte   TBLPTRU   = 0xFF8
#byte   TBLPTRH   = 0xFF7
#byte   TBLPTRL   = 0xFF6
#byte   TABLAT    = 0xFF5
#byte   PRODH     = 0xFF4
#byte   PRODL     = 0xFF3
#byte   INTCON    = 0xFF2
#byte   INTCON2   = 0xFF1
#byte   INTCON3   = 0xFF0
#byte   INDF0     = 0xFEF
#byte   POSTINC0  = 0xFEE
#byte   POSTDEC0  = 0xFED
#byte   PREINCO   = 0xFEC
#byte   PLUSW0    = 0xFEB
#byte   FSR0H     = 0xFEA
#byte   FSROL     = 0xFE9
#byte   WREG      = 0xFE8
#byte   INDF1     = 0xFE7
#byte   POSTINC1  = 0xFE6
#byte   POSTDEC1  = 0xFE5
#byte   PREINC1   = 0xFE4
#byte   PLUSW1    = 0xFE3
#byte   FSR1H     = 0xFE2
#byte   FSR1L     = 0xFE1
#byte   BSR       = 0xFE0
#byte   INDF2     = 0xFDF
#byte   POSTINC2  = 0xFDE
#byte   POSTDEC2  = 0xFDD
#byte   PREINC2   = 0xFDC
#byte   PLUSW2    = 0xFDB
#byte   FSR2H     = 0xFDA
#byte   FSR2L     = 0xFD9
#byte   STATUS    = 0xFD8
#byte   TMR0H     = 0xFD7
#byte   TMR0L     = 0xFD6
#byte   T0CON     = 0xFD5

#byte   OSCCON    = 0xFD3
#byte   HLVDCON   = 0xFD2
#byte   WDTCON    = 0xFD1
#byte   RCON      = 0xFD0
#byte   TMR1H     = 0xFCF
#byte   TMR1L     = 0xFCE
#byte   T1CON     = 0xFCD
#byte   TMR2      = 0xFCC
#byte   PR2       = 0xFCB
#byte   T2CON     = 0xFCA
#byte   SSPBUF    = 0xFC9
#byte   SSPADD    = 0xFC8
#byte   SSPSTAT   = 0xFC7
#byte   SSPCON1   = 0xFC6
#byte   SSPCON2   = 0xFC5
#byte   ADRESH    = 0xFC4
#byte   ADRESL    = 0xFC3
#byte   ADCON0    = 0xFC2
#byte   ADCON1    = 0xFC1
#byte   ADCON2    = 0xFC0
#byte   CCPR1H    = 0xFBF
#byte   CCPR1L    = 0xFBE
#byte   CCP1CON   = 0xFBD
#byte   CCPR2H    = 0xFBC
#byte   CCPR2L    = 0xFBB
#byte   CCP2CON   = 0xFBA

#byte   BAUDCON   = 0xFB8
#byte   PWM1CON   = 0xFB7
#byte   ECCP1AS   = 0xFB6
#byte   CVRCON    = 0xFB5
#byte   CMCON     = 0xFB4
#byte   TMR3H     = 0xFB3
#byte   TMR3L     = 0xFB2
#byte   T3CON     = 0xFB1
#byte   SPBRGH    = 0xFB0
#byte   SPBRG     = 0xFAF
#byte   RCREG     = 0xFAE
#byte   TXREG     = 0xFAD
#byte   TXSTA     = 0xFAC
#byte   RCSTA     = 0xFAB
#byte   EEADRH    = 0xFAA
#byte   EEADRR    = 0xFA9
#byte   EEDATA    = 0xFA8
#byte   EECON2    = 0xFA7
#byte   EECON1    = 0xFA6



#byte   IPR2      = 0xFA2
#byte   PIR2      = 0xFA1
#byte   PIE2      = 0xFA0
#byte   IPR1      = 0xF9F
#byte   PIR1      = 0xF9E
#byte   PIE1      = 0xF9D

#byte   OSCTUNE   = 0xF9B




#byte   TRISE     = 0xF96
   #bit     TRISE0   = 0xF96.0
   #bit     TRISE1   = 0xF96.1
   #bit     TRISE2   = 0xF96.2
   #bit     TRISE3   = 0xF96.3
   #bit     TRISE4   = 0xF96.4
   #bit     TRISE5   = 0xF96.5
   #bit     TRISE6   = 0xF96.6
   #bit     TRISE7   = 0xF96.7   
#byte   TRISD     = 0xF95
   #bit     TRISD0    = 0xF95.0
   #bit     TRISD1    = 0xF95.1
   #bit     TRISD2    = 0xF95.2
   #bit     TRISD3    = 0xF95.3
   #bit     TRISD4    = 0xF95.4
   #bit     TRISD5    = 0xF95.5
   #bit     TRISD6    = 0xF95.6
   #bit     TRISD7    = 0xF95.7
#byte   TRISC     = 0xF964
   #bit   TRISC0    = 0xF94.0
   #bit   TRISC1    = 0xF94.1
   #bit   TRISC2    = 0xF94.2
   #bit   TRISC3    = 0xF94.3
   #bit   TRISC4    = 0xF94.4
   #bit   TRISC5    = 0xF94.5
   #bit   TRISC6    = 0xF94.6
   #bit   TRISC7    = 0xF94.7
#byte   TRISB     = 0xF93
   #bit     TRISB0    = 0xF93.0
   #bit     TRISB1    = 0xF93.1
   #bit     TRISB2    = 0xF93.2
   #bit     TRISB3    = 0xF93.3
   #bit     TRISB4    = 0xF93.4
   #bit     TRISB5    = 0xF93.5
   #bit     TRISB6    = 0xF93.6
   #bit     TRISB7    = 0xF93.7
#byte   TRISA    = 0xF92
   #bit     TRISA0    = 0xF92.0
   #bit     TRISA1    = 0xF92.1
   #bit     TRISA2    = 0xF92.2
   #bit     TRISA3    = 0xF92.3
   #bit     TRISA4    = 0xF92.4
   #bit     TRISA5    = 0xF92.5
   #bit     TRISA6    = 0xF92.6
   #bit     TRISA7    = 0xF92.7






#byte   LATE      = 0xF8D
   #bit     LATE0    = 0xF8D.0
   #bit     LATE1    = 0xF8D.1
   #bit     LATE2    = 0xF8D.2
   #bit     LATE3    = 0xF8D.3
   #bit     LATE4    = 0xF8D.4
   #bit     LATE5    = 0xF8D.5
   #bit     LATE6    = 0xF8D.6
   #bit     LATE7    = 0xF8D.7
#byte   LATD      = 0xF8C
   #bit     LATD0    = 0xF8C.0
   #bit     LATD1    = 0xF8C.1
   #bit     LATD2    = 0xF8C.2
   #bit     LATD3    = 0xF8C.3
   #bit     LATD4    = 0xF8C.4
   #bit     LATD5    = 0xF8C.5
   #bit     LATD6    = 0xF8C.6
   #bit     LATD7    = 0xF8C.7
#byte   LATC      = 0xF8B
   #bit     LATC0    = 0xF8B.0
   #bit     LATC1    = 0xF8B.1
   #bit     LATC2    = 0xF8B.2
   #bit     LATC3    = 0xF8B.3
   #bit     LATC4    = 0xF8B.4
   #bit     LATC5    = 0xF8B.5
   #bit     LATC6    = 0xF8B.6
   #bit     LATC7    = 0xF8B.7
#byte   LATB      = 0xF8A
   #bit     LATB0    = 0xF8A.0
   #bit     LATB1    = 0xF8A.1
   #bit     LATB2    = 0xF8A.2
   #bit     LATB3    = 0xF8A.3
   #bit     LATB4    = 0xF8A.4
   #bit     LATB5    = 0xF8A.5
   #bit     LATB6    = 0xF8A.6
   #bit     LATB7    = 0xF8A.7
#byte   LATA      = 0xF89
   #bit     LATA0    = 0xF89.0
   #bit     LATA1    = 0xF89.1
   #bit     LATA2    = 0xF89.2
   #bit     LATA3    = 0xF89.3
   #bit     LATA4    = 0xF89.4
   #bit     LATA5    = 0xF89.5
   #bit     LATA6    = 0xF89.6
   #bit     LATA7    = 0xF89.7





#byte   PORTE     = 0xF84
   #bit     RE0   = 0xF84.0
   #bit     RE1   = 0xF84.1
   #bit     RE2   = 0xF84.2
   #bit     RE3   = 0xF84.3
   #bit     RE4   = 0xF84.4
   #bit     RE5   = 0xF84.5
   #bit     RE6   = 0xF84.6
   #bit     RE7   = 0xF84.7
#byte   PORTD     = 0xF83
   #bit     RD0   = 0xF83.0
   #bit     RD1   = 0xF83.1
   #bit     RD2   = 0xF83.2
   #bit     RD3   = 0xF83.3
   #bit     RD4   = 0xF83.4
   #bit     RD5   = 0xF83.5
   #bit     RD6   = 0xF83.6
   #bit     RD7   = 0xF83.7
#byte   PORTC     = 0xF82   
   #bit     RC0   = 0xF82.0
   #bit     RC1   = 0xF82.1
   #bit     RC2   = 0xF82.2
   #bit     RC3   = 0xF82.3
   #bit     RC4   = 0xF82.4
   #bit     RC5   = 0xF82.5
   #bit     RC6   = 0xF82.6
   #bit     RC7   = 0xF82.7   
#byte   PORTB     = 0xF81
   #bit     RB0   = 0xF81.0
   #bit     RB1   = 0xF81.1
   #bit     RB2   = 0xF81.2
   #bit     RB3   = 0xF81.3
   #bit     RB4   = 0xF81.4
   #bit     RB5   = 0xF81.5
   #bit     RB6   = 0xF81.6
   #bit     RB7   = 0xF81.7
#byte    PORTA    = 0xF80
   #bit     RA0   = 0xF80.0
   #bit     RA1   = 0xF80.1
   #bit     RA2   = 0xF80.2
   #bit     RA3   = 0xF80.3
   #bit     RA4   = 0xF80.4
   #bit     RA5   = 0xF80.5
   #bit     RA6   = 0xF80.6
   #bit     RA7   = 0xF80.7
   
// --------SERIAL PORT BITS---------------------------------- 
#BIT TX9  = TXSTA.6
#BIT TXEN = TXSTA.5
#BIT SYNC = TXSTA.4
#BIT BRGH = TXSTA.2

#BIT SPEN = RCSTA.7
#BIT RX9  = RCSTA.6
#BIT SREN = RCSTA.5
#BIT CREN = RCSTA.4
#BIT FERR = RCSTA.2
#BIT OERR = RCSTA.1

#BIT TXIE = PIE1.4 
#BIT RCIE = PIE1.5

#BIT RCIF = PIR1.5

//;----- INTCON Bits -----------------------------------------------------
#bit RBIF             =INTCON.0
#bit INT0F            =INTCON.1
#bit TMR0IF           =INTCON.2
#bit RBIE             =INTCON.3
#bit INT0E            =INTCON.4
#bit TMR0IE           =INTCON.5
#bit PEIE             =INTCON.6
#bit GIE              =INTCON.7

#bit INT0IF           =INTCON.1
#bit T0IF             =INTCON.2
#bit INT0IE           =INTCON.4
#bit T0IE             =INTCON.5
#bit GIEL             =INTCON.6
#bit GIEH             =INTCON.7

_________________
Thinh
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 06, 2013 1:18 pm     Reply with quote

I don't care what you want to do. If you use a driver written by someone
else, the driver will tell you how to use it. You must follow the
instructions in the driver to make it work correctly. If you invent your
own way, the driver will not work.

Fix the #define statements for the lcd pins the way that I showed in
my previous post.

Also fix the order of the #define statements and the #include for lcd.c
as shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=47663&start=1

If you do those two things, then you have a chance for the lcd to work.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group