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 CCS Technical Support

lcd with 16f676
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

lcd with 16f676
PostPosted: Thu Nov 27, 2014 8:20 am     Reply with quote

i was testing lcd code with 16f676. its not work. lcd show only black blocks.
Code:

/*     
        16F676 Configuration   
       

          O = Output, I = Input
                    _________
              Vdd   | 1  14 |  Vss
  (O)  L1 <-- RA5   | 2  13 |  AN0 <-- I\P Volt_Sense (I)
  (O)  L2 <-- RA4   | 3  12 |  AN1 <-- O\P Volt_Sense (I)
  (I) SW1 --> MCLR  | 4  11 |  RN2 <-- O\P Volt_Sense (I)
  (O) RS  <-- RC5   | 5  10 |  RC0 --> DB4 (O)
  (O)  E  <-- RC4   | 6   9 |  RC1 --> DB5 (O)
  (O) DB7 <-- RC3   | 7   8 |  RC2 --> DB6 (O)
                    ---------
*/
    #include <input_output.h>
     #include <lcd.c>

/*****************************************************************************
 ADC Defines
 ****************************************************************************/
#bit ADFM = 0x1F.7      // A/D Result Formed Select bit
            // 0=Left Justified, 1=Right Justified
#define ADC_AVERAGE_COUNT 100     // # of times to average ADC_Value
#define ADC_DELAY 1              // Change to "1" for 1 ms for real card
#define ADC_2TAD 1               // Wait 1 ms for 2TAD to complete before doing another AD conversion.


unsigned int16 ch_0, ch_1, ch_2;

 /*****************************************************************************
  Function prototypes
 ****************************************************************************/
int ProcessMains(void);
int16 getchreading(int channel);
void Process_display(void);

 /*****************************************************************************
  Main Program
 ****************************************************************************/
void main()
{
   disable_interrupts(GLOBAL);

   //ADC Init
   setup_adc_ports(sAN0 | sAN1 | sAN2);         // Setup AN0 and AN1 for analog
   setup_adc(ADC_CLOCK_DIV_8);
   ADFM = 1;                      //AD Result Right Justified
   setup_comparator(NC_NC);
   
  // enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   

   while (TRUE)
   {
 lcd_init();  // Always call this first.
 
      printf ( LCD_PutChar, "welcome\n" );
            printf ( LCD_PutChar, "holoo word" );

// Delay to make sure a minimum of 2 TADs have gone by before we do another measurement.
   delay_ms(1000); //1=5
   } // Loop Forever 


} // End Main



lcd file as
Code:
// flex_lcd.c

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

 #define LCD_DB4   PIN_C0
 #define LCD_DB5   PIN_C1
 #define LCD_DB6   PIN_C2
 #define LCD_DB7   PIN_C3

 #define LCD_E     PIN_C4
 #define LCD_RS    PIN_C5
 //#define LCD_RW    PIN_C5


// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

//#define USE_LCD_RW   1     

//========================================

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line


int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                    // Display on
 1,                      // Clear display
 6                       // Increment cursor
 };
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).
 output_bit(LCD_DB4, !!(nibble & 1));
 output_bit(LCD_DB5, !!(nibble & 2));
 output_bit(LCD_DB6, !!(nibble & 4));   
 output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 output_high(LCD_E);
 delay_us(2);
 output_low(LCD_E);
}

//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine.  For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.     

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3

retval = 0;
   
output_high(LCD_E);
delay_cycles(1);

retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
 
output_low(LCD_E);
   
return(retval);   
}   
#endif

//---------------------------------------
// Read a byte from the LCD and return it.

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;

output_high(LCD_RW);
delay_cycles(1);

high = lcd_read_nibble();

low = lcd_read_nibble();

return( (high<<4) | low);
}
#endif

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif

if(address)
   output_high(LCD_RS);
else
   output_low(LCD_RS);
     
 delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_E);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_E);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
   
    // If the R/W signal is not used, then
    // the busy bit can't be polled.  One of
    // the init commands takes longer than
    // the hard-coded delay of 60 us, so in
    // that case, lets just do a 5 ms delay
    // after all four of them.
    #ifndef USE_LCD_RW
    delay_ms(5);
    #endif
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void LCD_PutChar(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}

//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;

lcd_gotoxy(x,y);

// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));

output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);

return(value);
}
#endif

include input_output.h file as

Code:
#include <16F676.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal Oscillator @ 4 Mhz
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR              //No brownout reset
#FUSES PROTECT          //Code protected from reads

#use delay(clock=4000000)      // 4 Mhz Clock
#rom 0x3FF = {0x3480}

#use fixed_IO(A_outputs =PIN_A4,PIN_A5)
#use fixed_IO(C_outputs = PIN_C0,PIN_C1,PIN_C2,PIN_C3,PIN_C4,PIN_C5)


_________________
sahu
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 8:39 am     Reply with quote

Move LCD_init() before the While loop.
Place it right after enable_interrupts(global)

Then add a 500ms delay right after LCD_init()
It takes time for the display to initialize.
_________________
Google and Forum Search are some of your best tools!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 9:19 am     Reply with quote

You don't show the fuses etc., to set the chip up. Also the clock statement. What are they?. Or are they missing?. If the latter, then 'of course' it won't work.
Also you show MCLR going to a switch. What pulls it up to 5v, when the switch is not operated?. Unless this is done, the chip won't run.
As a comment you don't need to fiddle with ADFM. The compiler will justify the output for you, if you specify in the device statement: ADC=8 (8 bit right justified) ADC=10 (10 bit right justified) ADC=16 (10 bit left justified).
At the moment you are not using the ADC though....
Code:

#FUSES INTRC_IO,MCLR,BROWNOUT,NOPROTECT,NOCPD
#use delay(INTERNAL=4MHz)
#device ADC=10

Basic setup for internal 4MHz operation, with MCLR operating, and ADC giving 10bits, right justified.
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 10:13 am     Reply with quote

It seems he put the setup code at the bottom of his post in his input/output code
_________________
Google and Forum Search are some of your best tools!!!!
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 12:33 pm     Reply with quote

dyeatman wrote:
Move LCD_init() before the While loop.
Place it right after enable_interrupts(global)

Then add a 500ms delay right after LCD_init()
It takes time for the display to initialize.

sir tell me as
Code:
void main()
{
   disable_interrupts(GLOBAL);

   //ADC Init
   setup_adc_ports(sAN0 | sAN1 | sAN2);         // Setup AN0 and AN1 for analog
   setup_adc(ADC_CLOCK_DIV_8);
   ADFM = 1;                      //AD Result Right Justified
   setup_comparator(NC_NC);
   
  // enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
    lcd_init();  // Always call this first.
delay_ms(500);
   while (TRUE)
   {      printf ( LCD_PutChar, "welcome\n" );
            printf ( LCD_PutChar, "holoo word" );

// Delay to make sure a minimum of 2 TADs have gone by before we do another measurement.
   delay_ms(1000); //1=5
   } // Loop Forever


} // End Main



but same problem
_________________
sahu
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 12:41 pm     Reply with quote

You enable all the interrupts but without any ISRs that i can see..
that WILL cause huge problems...

jay
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 12:57 pm     Reply with quote

temtronic wrote:
You enable all the interrupts but without any ISRs that i can see..
that WILL cause huge problems...

jay

u tell here no need
enable_interrupts(GLOBAL);
.i comment out this .
nothing , help this . problem is same
by way i clear u i used 162A lcd
_________________
sahu
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 1:50 pm     Reply with quote

You placed the lcd_init() in the proper place and say you
removed the enable_interrupts(), that is good.

If it still doesn't work you likely have a wiring or LCD problem.
However, you are not even sure the processor is running.

So, these are the next steps:
1. Try to blink an LED connected to a pin to confirm the PIC is running
2. Post a link to the datasheet for your LCD
3. Tell us how the LCD pins are connected. Especially the VEE pin.
_________________
Google and Forum Search are some of your best tools!!!!
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 2:10 pm     Reply with quote

dyeatman wrote:
You placed the lcd_init() in the proper place and say you
removed the enable_interrupts(), that is good.

If it still doesn't work you likely have a wiring or LCD problem.
However, you are not even sure the processor is running.

So, these are the next steps:
1. Try to blink an LED connected to a pin to confirm the PIC is running
2. Post a link to the datasheet for your LCD
3. Tell us how the LCD pins are connected. Especially the VEE pin.


i check my wiring & LCD 2-3 times .also replace it that time

1.
Code:
 for(i=0;i<15;i++)
    {
      __delay_ms(200);
      output_high(PIN_A5);
    }

THIS IS OK ?
2.http://www.itron.com.cn/PDF_file/JHD162A%20SERIES.pdf

3.the VEE pin , i connect with 10k pot(preset). its work very well. wen i move it lcd contrast change fine .
_________________
sahu
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 2:33 pm     Reply with quote

Add one line below your delay in the main loop as shown below.

Code:
     
printf ( LCD_PutChar, "welcome\n" );
printf ( LCD_PutChar, "holoo word" );

// Delay to make sure a minimum of 2 TADs have gone by before we do another measurement.
   delay_ms(1000); //1=5
    output_toggle(PIN_A5);   <=======

_________________
Google and Forum Search are some of your best tools!!!!
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 2:39 pm     Reply with quote

BTW, you say the contrast varies just fine but you also say you get nothing
but "black blocks". Does the line of "black blocks" fade out as you adjust the
contrast?

Question: Is this in Proteus or in actual hardware?
_________________
Google and Forum Search are some of your best tools!!!!


Last edited by dyeatman on Thu Nov 27, 2014 3:01 pm; edited 1 time in total
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 2:43 pm     Reply with quote

dyeatman wrote:
BTW, you say the contrast varies just fine but you also say you get nothing
but "black blocks". Does

black [] contrast varies.not lcd display as i put my code
dyeatman wrote:

Question: Is this in Proteus or in actual hardware?

actual hardware
_________________
sahu
dyeatman



Joined: 06 Sep 2003
Posts: 1935
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 3:03 pm     Reply with quote

OK, if the led blinks about once per second when the program runs
then you are back to a hardware problem.
_________________
Google and Forum Search are some of your best tools!!!!
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Nov 27, 2014 3:08 pm     Reply with quote

dyeatman wrote:
OK, if the led blinks about once per second when the program runs
then you are back to a hardware problem.

ok i test it . then reply here
_________________
sahu
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

now ok its working
PostPosted: Thu Nov 27, 2014 3:35 pm     Reply with quote

dyeatman wrote:
OK, if the led blinks about once per second when the program runs
then you are back to a hardware problem.

meany meany thanks sir g
now ok
its working
_________________
sahu
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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