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 16x2 Powertip And IR code grabber

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



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

LCD 16x2 Powertip And IR code grabber
PostPosted: Mon Aug 24, 2009 11:31 am     Reply with quote

Hi all,

I bought this LCD 16x2: PC1602AR-GSO-A
I read on the Powertip homepage that the display has the ST7066U controller (http://www.powertip.com.tw/products_1.php?area_id=1170985616&area_name=Character%20LCD%20Module).
This site http://www.sitronix.com.tw/sitronix/product.nsf/Doc/ST7066U says that: "The ST7066U has pin function compatibility with the HD44780, KS0066 and SED1278 that allows the user to easily replace it with an ST7066U"

So, I tested this display with a 18F4550 this is the code:
Code:
#include <18F4550.h>
#device adc=8
#use delay(clock=20000000,RESTART_WDT)
#fuses HS, BROWNOUT, BORV20, PUT, STVREN, NOLVP
#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 
#include "lcd.c"

void main() {
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_ON);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   ext_int_edge(0,H_TO_L);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(global);

lcd_init(); //Initialise LCD
delay_ms(10);

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}


Nothing happens Crying or Very sad

In Proteus with a LCD Hitachi the code works correctly Confused
I have also tried with this code: http://www.ccsinfo.com/forum/viewtopic.php?t=21290
With:
E0 -->RS
E1 -->Enable
E2 -->RW
Nothing, in Proteus works, on my circuit nope :(

I checked the circuit 100 times, seems ok!
On the RS pin I read 5V like in Proteus Sad

Somebody can help me?
Thanks a lot


Last edited by Kova on Wed Aug 26, 2009 3:22 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 11:50 am     Reply with quote

Quote:

enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT);
enable_interrupts(global);

You are enabling interrupts without any interrupt routines. This will
cause the program to crash.

Quote:
setup_wdt(WDT_ON);

You are enabling the Watchdog Timer, but you don't have a restart_wdt()
line in your while() loop. This will cause the program to constantly reset.

Quote:
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_ON);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
ext_int_edge(0,H_TO_L);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT);
enable_interrupts(global);

You don't need this code. These modules are all disabled by default
upon power-on reset of the PIC. You don't need to do it again in code.
Delete all of the lines above.
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 12:03 pm     Reply with quote

PCM programmer wrote:
You don't need this code. These modules are all disabled by default
upon power-on reset of the PIC. You don't need to do it again in code.
Delete all of the lines above.


Sure sorry, I writed the old code in the new those lines are disabled.
This is the code that I have tested:
Code:

#include <18F4550.h>
#device adc=8
#use delay(clock=20000000,RESTART_WDT)
#fuses HS, BROWNOUT, BORV20, PUT, STVREN, NOLVP
#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 
#include "lcd.c"

void main() {
   /*setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_ON);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   ext_int_edge(0,H_TO_L);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(global);*/

lcd_init(); //Initialise LCD
delay_ms(10);

lcd_putc("\fHello World\n");
lcd_putc("Line Number 2");

while(1);
}


Thanks PCM Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 12:07 pm     Reply with quote

Is it now working ?

If not, then post what lcd driver you are using. Is it the Flex driver from
the Code library forum ? Or is it the CCS lcd.c driver ?

What is your compiler version ?
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 3:17 am     Reply with quote

PCM programmer wrote:
Is it now working ?

If not, then post what lcd driver you are using. Is it the Flex driver from
the Code library forum ? Or is it the CCS lcd.c driver ?

What is your compiler version ?


Wow...now it works!
I don't not why but this LCD works only if the Vee pin is connected to Ground Confused (without any trimmer/pot)..Bohh...

Now I have another little problem Rolling Eyes
I want to capture the signal from an IR Decoder (TMFS5000).
I searched on the forum and I have found many projects, but I want only to capture the "time of the code".

I'm explain with the code Laughing
Code:

#include <18F4550.h>
#use delay(clock=20000000)
#fuses NOWDT,HS, PUT, NOPROTECT, BROWNOUT, MCLR, NOLVP, NOCPD
#define LCD_ENABLE_PIN  PIN_E1 //E0                             
#define LCD_RS_PIN      PIN_E0 //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 
#include "lcd.c"

INT8  Counter=0;
INT16 time[32];
INT16 time2[32];
INT1  Received=0;
INT1  AltoBasso=0;
INT1  Falso=0;
INT1  Cicalino=0;


#int_EXT
void EXT_isr(void)
{
//It is necessary because when pic startup there is an interrupt
if (Falso==0)
{
set_timer1(0);
Falso=1;
return;
}

 time[counter]=get_timer1();
 set_timer1(0);
 counter++;
 
//Switch from High and Low
if (AltoBasso==0)
   {
      ext_int_edge(0,L_TO_H);
      AltoBasso=1;
   }
   else if (AltoBasso==1)
   {
      ext_int_edge(0,H_TO_L);
      AltoBasso=0;
   }

//Grab max 32 edge
  if (counter==32)
  {
   Received=1;
   disable_interrupts(INT_EXT);
  }
}

#int_TIMER1
void TIMER1_isr(void)
{
counter=0;
}

void AzzeraCode(void)
{
int i=0;
   for(i=0;i<32;i=i+1)
   {
   time[i]=0;
   }
}

void write_long_to_eeprom(int8 addr, int16 data)
{
 int8 i2;

 for(i2 = 0; i2 < 2; i2++)
     write_eeprom(addr + i2, *((int8*)&data + i2) ) ;
}

int16 read_long_from_eeprom(int8 addr)
{
int8 i2;
int16 data;

for(i2 = 0; i2 < 2; i2++)
   *((int8*)&data + i2) = read_eeprom(addr + i2);

return(data);
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   ext_int_edge(0,H_TO_L);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);
   
   lcd_init(); //Initialise LCD
   delay_ms(250);
   
   lcd_putc("\fHello\n");
   
   while(1)
   {
    int ct=0;
    int contatore=0;
   
    if(Received==1)
      {         
         counter = 0;
         Received = 0;

     if(cicalino==0)
     {
       for(ct=0;ct<32;ct=ct+1)
         {
            write_long_to_eeprom(ct*2, time[ct]);
            lcd_putc("Write\n");
         }
              for(ct=0;ct<32;ct=ct+1)
            {
               time2[ct] = read_long_from_eeprom(ct*2);
               lcd_putc("\fRead\n");
            }
      cicalino=1;
     }
     
     else if (cicalino==1)
     {
         for(ct=1;ct<32;ct=ct+1)
         {   
          if ( abs((time[ct]-time2[ct])) < 300) //Threshold
            {
              contatore = contatore +1;
            }
         }
         
         if (contatore >28) //Good?
            {
            lcd_putc("\fCorrect\n");
            }
         else
            {
            lcd_putc("\fNot Correct\n");
            }
         contatore = 0;
        }
       
       AzzeraCode();
       enable_interrupts(INT_EXT);
      }

   }
}


The problem is that when I grab a "same code" the time of each edge is always different!!!

P.S.
In the absence of IR light, the output of the decoder is normally high.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 11:54 am     Reply with quote

Describe the incoming signal to the PIC. What is the frequency and
the duty cycle ? Or, if it's an irregular pulse stream, then what is the
minimum pulse width? Post a link to a document that shows a timing
diagram of the pulses, if possible.
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

PostPosted: Wed Aug 26, 2009 12:03 pm     Reply with quote

PCM programmer wrote:
Describe the incoming signal to the PIC. What is the frequency and
the duty cycle ? Or, if it's an irregular pulse stream, then what is the
minimum pulse width? Post a link to a document that shows a timing
diagram of the pulses, if possible.


It's an irregular pulse stream, because I want to grab only one button from a generic remote controller.

The user push a button on the remote, the MCU grabs the code (the time of each pulse), saves the timing and associates a task.
So when the user push another time the button, the MCU reads the timing code and it compares with the timing saved in memory and if it's correct starts the task.

I don't know in advice the protocol used by the user's remote controller.
Do you think that is it possible to do that?

Thanks PCM for the help
Kova



Joined: 06 May 2007
Posts: 35

View user's profile Send private message

PostPosted: Fri Aug 28, 2009 4:49 am     Reply with quote

Arghh Nothing
I have used another IR Detector (TSOP1138...active LOW)..But nothing!!
It doesn't work correctly :(...The code is no always recognized
I write another code but..nope :( not work

Code:

#include <18F4550.h>
#device adc=8
#use delay(clock=20000000,RESTART_WDT)
#fuses HS, BROWNOUT, BORV20, PUT, STVREN, NOLVP

#define LCD_ENABLE_PIN  PIN_E1 //E0                               ////
#define LCD_RS_PIN      PIN_E0 //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 
#include "lcd.c"

unsigned INT32 time[32] = {0};
unsigned INT32 time2[32] = {0};
INT1  falso=0;
INT1  cicalino=0;

unsigned int8 rx_state = 0;
unsigned int32 timer_at_start, timer_at_end, low_time, timer_at_mid, period;
int1 data_avail = FALSE, caught_rise = TRUE;

#int_TIMER1
void TIMER1_isr(void) {
}

#int_EXT
void ext_isr(void) {
   if (caught_rise) { // this is a rising edge
      time[rx_state] = get_timer1();
     set_timer1(0);
      caught_rise = FALSE;
      rx_state++;
      ext_int_edge(0,H_TO_L);   
   }
   else { // this is a falling edge
      time[rx_state] = get_timer1();
      set_timer1(0);
     caught_rise = TRUE;
      ext_int_edge(0,L_TO_H);
      rx_state++;     
   }

   if (rx_state == 32) {
       disable_interrupts(INT_EXT);
       delay_ms(250);
       rx_state = 0;
       data_avail = TRUE;
   }
}

void AzzeraCode(void)
{
int i=0;
   for(i=0;i<32;i=i+1)
   {
   time[i]=0;
   }
}

void write_long_to_eeprom(int32 addr, unsigned int32 data)
{
 int8 i2;

 for(i2 = 0; i2 < 4; i2++)
     write_eeprom(addr + i2, *((int8*)&data + i2) ) ;
}

int32 read_long_from_eeprom(int32 addr)
{
int8 i2;
unsigned int32 data;

for(i2 = 0; i2 < 4; i2++)
   *((int8*)&data + i2) = read_eeprom(addr + i2);

return(data);
}

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_wdt(WDT_ON);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   ext_int_edge(0,L_TO_H);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_EXT);
   enable_interrupts(global); 
   set_tris_e(0x00);
   set_tris_c(0xff);
   port_b_pullups(FALSE);
   set_tris_b(0xff);
   
   lcd_init();
   delay_ms(250);
   lcd_putc("\fHello World\n");
   rx_state = 0;
   
   while(TRUE)
   {
    int ct=0;
    int contatore=0;
    restart_wdt();
   
   if (data_avail)
   {
       data_avail = FALSE;

       if(cicalino==0)
      {
          for(ct=0;ct<32;ct=ct+1)
         {
            write_long_to_eeprom(ct*4, time[ct]);
            lcd_putc("Scritto\n");
         }
            for(ct=0;ct<32;ct=ct+1)
         {
            time2[ct] = read_long_from_eeprom(ct*4);
            lcd_putc("\fLetto\n");
         }
        cicalino=1;
        }
     
        else if (cicalino==1)
        {
          for(ct=1;ct<32;ct=ct+1)
         {   
          if ( ((time[ct]-time2[ct]) < 150) || ((time2[ct]-time[ct]) < 150) )
            {
              contatore = contatore +1;
            }
         }
         if (contatore >30)
            {
         printf(lcd_putc,"\fCORRETTO = %u", contatore);
            }
         else
            {
         printf(lcd_putc,"\fNON CORRETTO = %u", contatore);
            }
         contatore = 0;
       }
 
      AzzeraCode();
      rx_state = 0;
     delay_ms(250);
     lcd_putc("\fWaiting");
      enable_interrupts(INT_EXT);

   }
   
}
}


Crying or Very sad Crying or Very sad Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 28, 2009 3:55 pm     Reply with quote

Describe the timing of the incoming signal completely.
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