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

setting 18f8722 to all digital

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



Joined: 04 Nov 2007
Posts: 2

View user's profile Send private message

setting 18f8722 to all digital
PostPosted: Mon Nov 05, 2007 1:58 pm     Reply with quote

This is my first time using the 18f8722 and I am having trouble setting a few pins for digital I/O.
I am running the PIC at 5 volts.
when running the code below the pins RG0, RG3, RG4, RE4, RJ5 all spike to 1.6-2.3 volts then decay to ground in about 1ms. All other pins function correctly.
I read elsewhere that this PIC has a rather large amount of registers that need to be set to use digital IO.
I'm using compiler version 3.222 which may be the problem but it does have the 18f8722 header file so I would assume it would support this PIC

In case you're wondering this program isn't the purpose of the PIC it was simply to test the soldering connections. I soldered a second PIC to rule out any soldering damage both PICs behave the same.

Code:

#include <18F8722.h>
#fuses INTRC,NOPUT,NOLVP,NOBROWNOUT,NOPROTECT,NOWDT
#use delay (clock=4000000)

//disable intterupts,CCP,ADC,timers, and PSP
SETUP_CCP1(CCP_OFF);
SETUP_CCP2(CCP_OFF);
SETUP_CCP3(CCP_OFF);
SETUP_CCP4(CCP_OFF);
SETUP_CCP5(CCP_OFF);
DISABLE_INTERRUPTS(GLOBAL);
DISABLE_INTERRUPTS(INT_RTCC);
DISABLE_INTERRUPTS(INT_TIMER0);
DISABLE_INTERRUPTS(INT_TIMER1);
DISABLE_INTERRUPTS(INT_TIMER2);
DISABLE_INTERRUPTS(INT_TIMER3);
DISABLE_INTERRUPTS(INT_EXT);
DISABLE_INTERRUPTS(INT_EXT1);
DISABLE_INTERRUPTS(INT_EXT2);
DISABLE_INTERRUPTS(INT_EXT3);
DISABLE_INTERRUPTS(INT_RB);
DISABLE_INTERRUPTS(INT_PSP);
DISABLE_INTERRUPTS(INT_AD);
DISABLE_INTERRUPTS(INT_RDA);
DISABLE_INTERRUPTS(INT_TBE);
DISABLE_INTERRUPTS(INT_SSP);
DISABLE_INTERRUPTS(INT_CCP1);
DISABLE_INTERRUPTS(INT_CCP2);
DISABLE_INTERRUPTS(INT_BUSCOL);
DISABLE_INTERRUPTS(INT_LOWVOLT);
DISABLE_INTERRUPTS(INT_COMP);
DISABLE_INTERRUPTS(INT_EEPROM);
DISABLE_INTERRUPTS(INT_RDA2);
DISABLE_INTERRUPTS(INT_TBE2);
DISABLE_INTERRUPTS(INT_TIMER4);
DISABLE_INTERRUPTS(INT_CCP3);
DISABLE_INTERRUPTS(INT_CCP4);
DISABLE_INTERRUPTS(INT_CCP5);
DISABLE_INTERRUPTS(INT_OSCF);
SETUP_ADC( ADC_OFF );
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_PSP(DISABLED);
SETUP_TIMER_0(RTCC_OFF);
SETUP_TIMER_1(T1_DISABLED);
SETUP_TIMER_2(T2_DISABLED);
SETUP_TIMER_3(T3_DISABLED);
SETUP_TIMER_4(T4_DISABLED);


void main()
{
int ryt;
int rit,rot,rpt;

rit = 31780;

     while(1)
   {
      output_A(0x00);
      output_B(0x00);
      output_C(0x00);
      output_D(0x00);
      output_E(0x00);
      output_F(0x00);
      output_H(0x00);
      output_J(0x00);
      delay_ms(500);
      output_A(0xFF);
      output_B(0xFF);
      output_C(0xFF);
      output_D(0xFF);
      output_E(0xFF);
      output_F(0xFF);
      output_H(0xFF);
      output_J(0xFF);
      delay_ms(500);

   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 05, 2007 2:10 pm     Reply with quote

1. You don't need those statements to disable interrupts. They are all
disabled upon power-on reset anyway. Those statements just clutter up
your program. Same thing for the CCP modules.

2. See this post about disabling the External Memory Interface.
http://www.ccsinfo.com/forum/viewtopic.php?t=23622

3. There are no lines in your program to toggle the Port G pins.
jholden



Joined: 04 Nov 2007
Posts: 2

View user's profile Send private message

PostPosted: Mon Nov 05, 2007 7:42 pm     Reply with quote

Thanks, but I still can't get Pin E4 to function as a digital IO.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Nov 06, 2007 3:05 am     Reply with quote

Code:
int rit,rot,rpt;

rit = 31780;
Note that in the CCS compiler the integers have an 8 bit size by default, the value of 31780 doesn't fit. In order to avoid errors like this it is good practice to use the variable types int8, int16, int32, etc., this make your program also easier to port to another compiler.

Then there is a combination of two bugs:
1) All your program code _must_ be included inside a function, i.e. the CCP, timer and interrupt functions can not be placed in the 'open' like you have now. Check the list file (*.lst) and you will see no code is generated for these lines.
2) The compiler not complaining about (1) is a compiler bug.


Having moved your initialisation code into the main function I got an error for
Code:
  SETUP_PSP(DISABLED);
DISABLED is unknown and is to be replaced by PSP_DISABLED.

Timer2 and 4 setup contain a syntax error, there are missing parameters.

Not tested, but at least an improvement:
Code:
#include <18F8722.h>
#fuses INTRC,NOPUT,NOLVP,NOBROWNOUT,NOPROTECT,NOWDT
#use delay (clock=4000000)

#byte MEMCON = 0xF9C
#bit  EBDIS_BIT = MEMCON.7


void main()
{
   EBDIS_BIT = 1;   // Disable external memory interface
 
   // disable interupts,CCP,ADC,timers, and PSP
   SETUP_CCP1(CCP_OFF);
   SETUP_CCP2(CCP_OFF);
   SETUP_CCP3(CCP_OFF);
   SETUP_CCP4(CCP_OFF);
   SETUP_CCP5(CCP_OFF);
   DISABLE_INTERRUPTS(GLOBAL);
   SETUP_ADC( ADC_OFF );
   SETUP_ADC_PORTS(NO_ANALOGS);
   SETUP_PSP(PSP_DISABLED);
   SETUP_TIMER_0(RTCC_OFF);
   SETUP_TIMER_1(T1_DISABLED);
   SETUP_TIMER_2(T2_DISABLED,0,1);
   SETUP_TIMER_3(T3_DISABLED);
   SETUP_TIMER_4(T4_DISABLED,0,1);
 
   while(1)
   {
      output_A(0x00);
      output_B(0x00);
      output_C(0x00);
      output_D(0x00);
      output_E(0x00);
      output_F(0x00);
      output_G(0x00);
      output_H(0x00);
      output_J(0x00);
      delay_ms(500);
      output_A(0xFF);
      output_B(0xFF);
      output_C(0xFF);
      output_D(0xFF);
      output_E(0xFF);
      output_F(0xFF);
      output_G(0xFF);
      output_H(0xFF);
      output_J(0xFF);
      delay_ms(500);
   }
}
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