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

PCD: Converting 18F code to PIC24
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ramsey
Guest







PostPosted: Tue Oct 06, 2009 10:35 am     Reply with quote

Code:
   while(TRUE)
   {
      k=kbd_getc();
      if(k!=0)
      {
         if(k=='*')
          printf(eaDogM_WriteChr,"*");
         else
         printf(eaDogM_WriteChr,"%c",k);
      }
     }
Ramsey
Guest







PostPosted: Wed Oct 07, 2009 1:13 pm     Reply with quote

I cant find any error that could lead to problems with interfacing the keypad.
Any idea what could be wrong in code conversion ?

Ramsey
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 1:21 pm     Reply with quote

I see a few bugs in your code or in your presentation of it.

The code that you posted, uses pins only on Port B:
Quote:
//Keypad connection:
#define row0 PIN_B4
#define row1 PIN_B5
#define row2 PIN_B6
#define row3 PIN_B7
#define col0 PIN_B0
#define col1 PIN_B1
#define col2 PIN_B2
#define col3 PIN_B3


But then, you are turning on pullups for Port C pins, not Port pin B0-B3:
Quote:
void kbd_init()
{
//set_tris_b(0xF0);
//output_b(0xF0);
set_pullup(true, pin_B4);
set_pullup(true, pin_B5);
set_pullup(true, pin_B6);
set_pullup(true, pin_B7);
set_pullup(true, pin_C1); // on c port
set_pullup(true, pin_C2);
set_pullup(true, pin_C3);
set_pullup(true, pin_C4);
}


Also, in your posted PCD code, you have two conflicting oscillator fuses.
You should only have one oscillator fuse.
Quote:
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //High speed Osc
#FUSES XT
#FUSES NOIOL1WAY //multiple reconfigurations of pins


Post your current PCD keypad driver and test program.
Ramsey
Guest







PostPosted: Fri Oct 09, 2009 2:19 am     Reply with quote

Part with includes and LCD setup- just for LCD
Code:

//========Keypad part====================
#bit CN6PUE =  0x6E.14  // RB4   
#bit CN24PUE = 0x6E.15  // RB3   
#bit CN25PUE = 0x70.0   // RB2   
#bit CN45PUE = 0x6C.12  // RB1   

#bit CN48PUE = 0x72.0   // RC4
#bit CN47PUE = 0x70.15  // RC3
#bit CN46PUE = 0x70.14  // RC2
#bit CN45PUE = 0x70.13  // RC1


//Keypad connection:
#define row0 PIN_B1 
#define row1 PIN_B2 
#define row2 PIN_B3 
#define row3 PIN_B4 
#define col0 PIN_C1
#define col1 PIN_C2
#define col2 PIN_C3
#define col3 PIN_C3

// Keypad layout:
char const KEYS[4][4] =
{{'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}};


#define KBD_DEBOUNCE_FACTOR 23

void kbd_init()
{
//set_tris_b(0xF0);
//output_b(0xF0);
/*
set_pullup(true, pin_B4);
set_pullup(true, pin_B5);
set_pullup(true, pin_B6);
set_pullup(true, pin_B7);
set_pullup(true, pin_C1);
set_pullup(true, pin_C2);
set_pullup(true, pin_C3);
set_pullup(true, pin_C4);
*/
}

int8 ALL_ROWS (void)
{
if(input (row0) & input (row1) & input (row2) & input (row3))
   return (0);
else
   return (1);
}

char kbd_getc()
{
   static byte kbd_call_count;
   static int8 kbd_down;
   static char last_key;
   static byte col;
   
   byte kchar;
   byte row;
   
   kchar='\0';
   
   if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)
     {
      switch (col)
        {
         case 0:
           output_low(col0);
         output_high(col1);
         output_high(col2);
         output_high(col3);
           break;
         case 1:
           output_high(col0);
         output_low(col1);
         output_high(col2);
         output_high(col3);
           break;
         case 2:
           output_high(col0);
         output_high(col1);
         output_low(col2);
         output_high(col3);
           break;
         case 3:
           output_high(col0);
         output_high(col1);
         output_high(col2);
         output_low(col3);
           break;
         }
   
      if(kbd_down)
        {
         if(!ALL_ROWS())
           {
            kbd_down=false;
            kchar=last_key;
            last_key='\0';
           }
        }
      else
        {
         if(ALL_ROWS())
           {
            if(!input (row0))         row=0;
            else if(!input (row1))    row=1;
            else if(!input (row2))    row=2;
            else if(!input (row3))    row=3;
            last_key =KEYS[row][col];
            kbd_down = true;
           }
         else
           {
            ++col;
            if(col==4)
               col=0;
           }
        }
      kbd_call_count=0;
     }
   return(kchar);
}

//===========================
void main()
{
        lcd_init();
   char k;
      kbd_init();
   
   CN6PUE  = 1;
   CN24PUE = 1;
   CN25PUE = 1;
   CN45PUE = 1;
   CN48PUE = 1;
   CN47PUE = 1;
   CN46PUE = 1;
   //CN45PUE = 1;

   //-- for LCD -- start
       setup_spi (FALSE);
       setup_spi2(FALSE);
       setup_wdt(WDT_ON);
       setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
       // -- for LCD -- end

   printf(lcd_putc, "Program start");
   delay_ms(2000);


   while(TRUE)
   {
      k=kbd_getc();
      if(k!=0)
      {
         if(k=='*')
         printf(lcd_putc,k);
         else
         printf(lcd_putc,"%c",k);
      }
     }

} // main

LCD is non standard 2x16.
And I can see the "Program start" part on the LCD.
I removed the fuses XT line.
R.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 12:14 pm     Reply with quote

I see the following problems:

Quote:

//Keypad connection:
#define row0 PIN_B1
#define row1 PIN_B2
#define row2 PIN_B3
#define row3 PIN_B4
#define col0 PIN_C1
#define col1 PIN_C2
#define col2 PIN_C3
#define col3 PIN_C3

You have col2 and col3 both defined as PIN_C3.


Quote:

//========Keypad part====================
#bit CN6PUE = 0x6E.14 // RB4 CN6PUE is really on 0x6C.6
#bit CN24PUE = 0x6E.15 // RB3 C24PUE is really on 0x6E.8
#bit CN25PUE = 0x70.0 // RB2 CN25PUE is really on 0x6E.9
#bit CN45PUE = 0x6C.12 // RB1 CN45PUE is really on 0x70.13

#bit CN48PUE = 0x72.0 // RC4
#bit CN47PUE = 0x70.15 // RC3
#bit CN46PUE = 0x70.14 // RC2
#bit CN45PUE = 0x70.13 // RC1

Four of the #bit statements for the Pull-up enables have the wrong
register address and bit numbers.

You need to learn to continuously scan your code for errors, and also
to suspect that something might not be correct, and to check everything.
Ramsey
Guest







PostPosted: Sun Oct 11, 2009 11:21 am     Reply with quote

Thank you for your corrections.
I changed the settings and corrected the define part.

Compiled without errors, but still no keypress result.

Do you need the disassembler listing ?
Maybe this could help us out.

R.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 11:26 am     Reply with quote

I don't have the PCD compiler, so I can't do any low-level checking
of the code that I do for other compilers. I made the suggestions in this
thread just by proof-reading your code for errors. I'm not sure if I can
help any more.
Ramsey
Guest







PostPosted: Sun Oct 11, 2009 11:42 am     Reply with quote

Don't give up :-)

I see that FvM, Bkamen, Ttelmah, and you are only ones writing answers to PIC24. I know that you don't use PIC24.
------------------------------------------------

To be honest I don't think that this could be error with PCD.
The code is straightforward and there are just two functions that can be a problem with PICD24. KBD_GETC and KBD_INIT.

Kbd init I know not loaded but bit is set and initialized, or ?
----------------------------------------------
It must be something simple...


R.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 1:50 pm     Reply with quote

OK, I can do more checking.
Quote:

//-- for LCD -- start
setup_spi (FALSE);
setup_spi2(FALSE);
setup_wdt(WDT_ON);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
// -- for LCD -- end

You don't need any of this code. The SPI modules and the Timer are
already disabled upon power-on reset. You don't need to do it again
in code. Also, you are turning on the Watchdog Timer, but you don't
have any calls to the restart_wdt() function. You don't need the
Watchdog Timer in a test program. Delete all the lines of code above.

You didn't post your #fuses. If you have WDT enabled in your fuses,
change it to NOWDT.
Ramsey
Guest







PostPosted: Sun Oct 11, 2009 2:13 pm     Reply with quote

OK. I disabled this part.
This are the fuses.
They were primary set for LCD.
Code:

#include <24FJ256GB110.h>
#device ADC=10
#device PASS_STRINGS=IN_RAM

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   
#FUSES NOWRT                   
#FUSES ICSP1                   
#FUSES NOWINDIS                 
#FUSES WPRES128                 
#FUSES WPOSTS16               
#FUSES IESO                     
#FUSES NOCKSFSM               
#FUSES NOOSCIO                 
#FUSES HS           
#FUSES WPEND_LOW             
#FUSES NOWPCFG               
#FUSES NOWPDIS               
#FUSES WPFP0   
#FUSES PLL3                     
#FUSES RESERVED                 
#use delay(clock=24000000)

R.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 2:17 pm     Reply with quote

What is your external crystal frequency ? (or external oscillator freq, if
applicable).
Ramsey
Guest







PostPosted: Sun Oct 11, 2009 2:42 pm     Reply with quote

Main working frequency is 24Mhz as same as the frequency of the main oscillator.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 3:00 pm     Reply with quote

When I have a similar problem with a non working code or hardware (sometimes the kind of problem isn't obvious), I use e.g. a multimeter and single step the code. Check, if the intended outputs are switched, if the input signals are seen ate the port SFR and so on.

By the way, why do you use pullup-resistors at the column output pins?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 3:04 pm     Reply with quote

Quote:

Main working frequency is 24Mhz as same as the frequency of the main oscillator.

#FUSES HS
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP0
#FUSES PLL3
#FUSES RESERVED
#use delay(clock=24000000)

FvM is now helping, and he can probably help a lot more than I can.
But you asked to help a little more, so my question is, if you have a
24 MHz external oscillator, and your #use delay() is set for 24 MHz,
why do you have the PLL3 fuse set ?
Ramsey
Guest







PostPosted: Sun Oct 11, 2009 3:22 pm     Reply with quote

PCM:
I set the PLL fuse for the LCD.
Should I remove it ?

FVM:
I tested with multimeter but didn't get any result.
It looks like that the pic isn't opening the ports.
The hardware is connected OK, so this can not be the error.

Pullup resistors.
- I was thinking about that too. Maybe this could be the problem.
In the first design I had HW resistors set on the columns. It didn't work.
I removed them and set the SW resistors to see if this is the problem.
It didn't work also :-)

What do you suggest ?
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 Previous  1, 2, 3  Next
Page 2 of 3

 
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