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

PCH - IO Problem

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







PCH - IO Problem
PostPosted: Thu Mar 20, 2003 2:56 pm     Reply with quote

I have a series of programs that worked fine on a 16F877 that I am porting to an 18F458. My Keyboard routines that work fine on the 877 do not work on the 458. I have been able to strip the code to the minimum amount that demonstrates the problem.

I suspect I am missing something simple --- like a fuse or something. Spent two days on this --- time to look for help.

I am running 3.148 of the compiler on a Win2k machine. Target board is the Micro Engineering X1 Board.

//****************************************************************************************

#ifdef __PCH__
#include <18F458.h>
#fuses HS,NOWDT,WDT1,NOLVP
#else
#include <16f877.h>
#fuses HS,NOWDT,NOLVP
#endif

#use delay(clock=20000000)

#use rs232(baud=9600, parity=n, xmit=PIN_C6, rcv=PIN_C7, bits=8)
#use FAST_IO(B)

void KbdInit(void);
unsigned ReadKeyboard(int1 Hold);

void main() {

unsigned Key;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);

#ifdef __PCH__
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(FALSE);
setup_wdt(WDT_OFF);
#endif

KbdInit();
while(1){
Key = ReadKeyboard(1);
if (Key>0)
printf("\n\r KeyPress = \%d", Key);
}
}
//************************************************
void KbdInit(void)
{
port_b_pullups(TRUE);
}
//************************************************
unsigned ReadKeyboard(int1 Hold)
{
unsigned Mask, Col, Row, Key;

/* See if any keys are pressed */
SET_TRIS_B(0);
OUTPUT_B(0);
SET_TRIS_B(0xF0);

Key = INPUT_B();
if (Key == 0xF0)
return(0);

/* When no Key is pressed, "Key" contains:
0x00 on the 18F458 and
0xF0 on the 16F877
0xF0 is the desired response
*/
printf("\n\n\rKey Press \%2X", Key);

//* Code Snipped

return(0);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12894
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: PCH - IO Problem
PostPosted: Thu Mar 20, 2003 4:16 pm     Reply with quote

:=
:=I have a series of programs that worked fine on a 16F877 that I am porting to an 18F458. My Keyboard routines that work fine on the 877 do not work on the 458. I have been able to strip the code to the minimum amount that demonstrates the problem.
:=
:=I suspect I am missing something simple --- like a fuse or something. Spent two days on this --- time to look for help.
:=
:=I am running 3.148 of the compiler on a Win2k machine. Target board is the Micro Engineering X1 Board.
:=
:=//****************************************************************************************
:=
:=#ifdef __PCH__
:= #include <18F458.h>
:= #fuses HS,NOWDT,WDT1,NOLVP
:=#else
:= #include <16f877.h>
:= #fuses HS,NOWDT,NOLVP
:=#endif
:=
:=#use delay(clock=20000000)
:=
:=#use rs232(baud=9600, parity=n, xmit=PIN_C6, rcv=PIN_C7, bits=8)
:=#use FAST_IO(B)
:=
:=void KbdInit(void);
:=unsigned ReadKeyboard(int1 Hold);
:=
:=void main() {
:=
:=unsigned Key;
:=
:= setup_adc_ports(NO_ANALOGS);
:= setup_adc(ADC_CLOCK_DIV_2);
:= setup_psp(PSP_DISABLED);
:= setup_spi(FALSE);
:= setup_timer_0(RTCC_INTERNAL);
:= setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
:= setup_timer_2(T2_DISABLED,0,1);
:=
:= #ifdef __PCH__
:= setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
:= setup_comparator(FALSE);
:= setup_wdt(WDT_OFF);
:= #endif
:=
:= KbdInit();
:= while(1){
:= Key = ReadKeyboard(1);
:= if (Key>0)
:= printf("\n\r KeyPress = \%d", Key);
:= }
:=}
:=//************************************************
:=void KbdInit(void)
:={
:= port_b_pullups(TRUE);
:=}
:=//************************************************
:=unsigned ReadKeyboard(int1 Hold)
:={
:= unsigned Mask, Col, Row, Key;
:=
:= /* See if any keys are pressed */
:= SET_TRIS_B(0);
:= OUTPUT_B(0);
:= SET_TRIS_B(0xF0);
:=
:= Key = INPUT_B();
:= if (Key == 0xF0)
:= return(0);
:=
:=/* When no Key is pressed, "Key" contains:
:= 0x00 on the 18F458 and
:= 0xF0 on the 16F877
:= 0xF0 is the desired response
:=*/
:=printf("\n\n\rKey Press \%2X", Key);
:=
:=//* Code Snipped
:=
:= return(0);


It may be as simple as using a delay to allow the port to change directions before reading it. It takes a noticable time for it to switch directions.

SET_TRIS_B(0xF0);
delay_cycles(2);
Key = INPUT_B();


:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12900
Jerry Finsen
Guest







Re: PCH - IO Problem
PostPosted: Thu Mar 20, 2003 4:36 pm     Reply with quote

It was that simple! Thanks. Now to find where in the Data Sheet that little bit of information is found! It must be in there somewhere.

Thanks again

jerry

:=It may be as simple as using a delay to allow the port to change directions before reading it. It takes a noticable time for it to switch directions.
:=
:=SET_TRIS_B(0xF0);
:=delay_cycles(2);
:=Key = INPUT_B();
:=
:=
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12901
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