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
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

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

I don't think I can help any more.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

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

Quote:
I tested with multimeter but didn't get any result.
It looks like that the pic isn't opening the ports.

Sounds unlikely. "Not opening the port" is very vague, however. Are you sure, that your code is executed? Did you verify the port C pins are set to output? Can be verified with a multimeter as well. If not, you possibly have fast_io mode in effect and didn't set the TRIS register? You didn't show your full code, I think, so this can't be seen from your post. Personally, I don't believe, that the registers are set correctly, unless I checked with a debugger.

Also the PCD version hasn't been mentioned yet. Would be no fun to hear finally about an incredible outdated version, that doesn't know correct GB110 register addresses...
Guest








PostPosted: Mon Oct 12, 2009 4:27 am     Reply with quote

The only thing that is missing is the code is the tris settings.
This should be the whole code :-)

Code:

//--------TRIS settings---------------
//AD1PCFG = 0xFFFF;  // set all digital
#byte TRISB = 0x2C8
#byte TRISC = 0x2D0
 
// -- main --
set_tris_b= 0xffff;
set_tris_c =0xffff;

I was using the output_X before and the code compiled OK, but if i want to use set_tris then i cant compile. Just an addition to the upper text.

The part that I didn't send before, and that has to do with keypad is the one written above.

Did I miss something ?
Ramsey
Guest







PostPosted: Mon Oct 12, 2009 4:28 am     Reply with quote

PCD: 4.093
R.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 7:57 am     Reply with quote

No TRIS control would be necessary in standard_io mode (default if not explicitely specifying a different mode). With fast_io mode, it's wrong to set row pins B1..B4 to output (set_tris_b= 0xffff). I don't want to suggest anything in this regard, I was just asking about the used IO mode.

Quote:
but if i want to use set_tris then i cant compile
Why?

V4.093 should be O.K. for basic operation.
Ramsey
Guest







PostPosted: Tue Oct 13, 2009 6:00 am     Reply with quote

Code:
//---------------------------
#opt 9
//----------------------------
unsigned int const portb_settings = 0x0000;
unsigned int const portc_settings = 0x0000;
//========Keypad part====================
#bit CN6PUE =  0x6C.6   // RB4   
#bit CN24PUE = 0x6E.8   // RB3   
#bit CN25PUE = 0x6E.9   // RB2   
#bit CN45PUE = 0x70.13  // 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_C4

// 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;

   //-------------------------
   setup_adc_ports(NO_ANALOGS);
   set_tris_b(portb_settings);
    set_tris_c(portc_settings);
   //-------------------------

   //-- 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
 

This is now the latest code.
It's compiled without errors and these are the multimeter values:

Columns C2 and C3 have 3,3V and on key press value is set to 1V.
C2 = 2580 , C3 = 369#

Rest of the keys are not working.

Suggestions ?
Ramsey
Guest







PostPosted: Tue Oct 13, 2009 6:01 am     Reply with quote

Code:
//---------------------------
#opt 9
//----------------------------
unsigned int const portb_settings = 0x0000;
unsigned int const portc_settings = 0x0000;
//========Keypad part====================
#bit CN6PUE = 0x6C.6 // RB4
#bit CN24PUE = 0x6E.8 // RB3
#bit CN25PUE = 0x6E.9 // RB2
#bit CN45PUE = 0x70.13 // 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_C4

// 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;

//-------------------------
setup_adc_ports(NO_ANALOGS);
set_tris_b(portb_settings);
set_tris_c(portc_settings);
//-------------------------

//-- 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
Ramsey
Guest







PostPosted: Wed Oct 14, 2009 1:37 pm     Reply with quote

I still can get any key press result on LCD.
I put some string in while loop to see if this part of the code is executed.

Code:
while(TRUE)
   {
      k=kbd_getc();
       printf(lcd_putc,"I see you");  // i can see this
      if(k!=0)
      {
         if(k=='*')
         printf(lcd_putc,"I see you");  // I Can not see this part
         printf(lcd_putc,k);
         else
         printf(lcd_putc,"I see you");  // I Can not see this part
         printf(lcd_putc,"%c",k);
      }
     }



Any idea guys ?. Could it be in kbd_getc function ?
I tried to set other portb and portc settings.
Nothing happened.

Idea, suggestion ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 14, 2009 1:40 pm     Reply with quote

Quote:
I still can get any key press result on LCD.

Do you really mean you can't (can not) get a key press result ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 1:55 am     Reply with quote

I already suggested a test method:
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 at the port SFR and so on.

Unless you don't figure out, which action is failing (set the column select, read in the row data) you can't proceed, I fear.
W_Schauberg



Joined: 17 Sep 2009
Posts: 16

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 1:55 am     Reply with quote

It works for me.
Ramsey
Guest







PostPosted: Thu Oct 15, 2009 5:42 am     Reply with quote

Yes, it was hardware error. Unbelievable.
It's working perfect!. Don't know what to say accept ... unbelievable.

Thank you guys for all your help.
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
Page 3 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