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

port A using for input in pic18f4431

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



Joined: 19 Oct 2013
Posts: 19
Location: salam

View user's profile Send private message

port A using for input in pic18f4431
PostPosted: Thu Aug 28, 2014 11:40 pm     Reply with quote

I am using pic18f4431, connected lcd in port D, leds connected in port B, switches connected in port A and E. Program is working well but when the switch is closed my controller goes to reset and restarts.

Code:
#include <18F4431.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
//#FUSES BROWNOUT                 //Reset when brownout detected
//#FUSES BORV27                   //Brownout reset at 2.7V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOWINEN                  //WDT Timer Window Disabled
#FUSES T1LOWPOWER               //Timer1 low power operation when in sleep
#FUSES HPOL_HIGH                //High-Side Transistors Polarity is Active-High (PWM 1,3,5 and 7)
   //PWM module high side output pins have active high output polarity
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPOL_HIGH                //Low-Side Transistors Polarity is Active-High (PWM 0,2,4 and 6)
   //PWM module low side output pins have active high output polar
#FUSES PWMPIN                   //PWM outputs disabled upon Reset
#FUSES MCLR                     //Master Clear pin enabled
#FUSES FLTAC1                   //FLTA input is multiplexed with RC1
#FUSES SSP_RC                   //SCK/SCL=RC5, SDA/SDI=RC4, SDO=RC7
//#FUSES PWM4B5                   //PWM4 output is multiplexed on RB5
//#FUSES EXCLKC3                  //TMR0/T5CKI external clock input is muliplexed with RC3

#use delay(clock=20000000)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

i am using this header file, same program worked successfully in pic16f877a i need more ROM so i selected pic18f4431 pls help me pls..........
Ttelmah



Joined: 11 Mar 2010
Posts: 19255

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 12:37 am     Reply with quote

Critical fuse to change before anything else, is LVP change to NOLVP.

LVP, is _only_ used when using a low voltage programmer. All normal programmers are _not_ low voltage. With this fuse enabled, B5, can no longer be used for normal I/O, and if you put a signal on this pin, the chip will reset (at the least).

You really should have PUT when using a crystal. That is the whole 'point' of this fuse, to allow the crystal oscillator time to start.

Understand something else. Removing a fuse doesn't necessarily turn the feature 'off'. It depends what the default 'un-programmed' state is. So for example, your chip actually has 'BROWNOUT' enabled, since this is the default state. If you don't want this, you need to select the 'NOBROWNOUT' fuse setting. Just remming out the BROWNOUT fuse, and the voltage, leaves the chip set to enable brownout, at 2v.

You also have PWMPIN selected, which means that most of the portB pins are connected to the PWM controller on boot. You need 'NOPWMPIN' to disable this.

To see what fuses are enabled, load the LST file, at the end, it has all the fuses that are set. Then the data sheet tells you what they 'do'.
deenadayalan



Joined: 19 Oct 2013
Posts: 19
Location: salam

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 3:20 am     Reply with quote

thank you sir
deenadayalan



Joined: 19 Oct 2013
Posts: 19
Location: salam

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 5:40 am     Reply with quote

I got output sir, thank you for your valuable guidance. One more doubt sir, I used A1 for adc and connected B7,B6,B5 with leds. I got output in Proteus simulation but i didnt get output in real time. Led continued high state, also value=0. I am using pic18f4431 controller. Sir pls help me sir.

my coding
Code:
void main()
{
   float value=0;
   //port_b_pullups (false);
   set_tris_b(0x00);
   set_tris_a(0xff);
   output_b(0x00);

   setup_adc (1);
   setup_adc_ports( ALL_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL ); 
         
   while(true)
   {
       set_adc_channel(1);
       delay_us(10);
       value = read_adc();
       if(value>0)
          output_high(pin_b7);
       else
          output_low(pin_b7);
       if(value>100)
          output_high(pin_b6);
       else
          output_low(pin_b6);
       if(value>200)
          output_high(pin_b4);
       else
          output_low(pin_b4);
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 10:40 pm     Reply with quote

This post shows a program for the 18F4431 which displays the ADC value
on a terminal program in Windows (example: TeraTerm):
http://www.ccsinfo.com/forum/viewtopic.php?t=40279&start=3
It's much better to use a terminal program for debugging, instead of LEDs.
You can see the results from the ADC.
Ttelmah



Joined: 11 Mar 2010
Posts: 19255

View user's profile Send private message

PostPosted: Fri Aug 29, 2014 11:49 pm     Reply with quote

Let's also point out that the value from the ADC, is an integer, not a float, and so the code as written has to convert this to a float, and then convert all the integer comparison values to floats, and do the much more complex comparison on these. Think again....

Proteus will work, even if the clock circuit is wrong. Have you actually checked the chip is running?.
deenadayalan



Joined: 19 Oct 2013
Posts: 19
Location: salam

View user's profile Send private message

PostPosted: Sat Aug 30, 2014 5:31 am     Reply with quote

Dear Ttelmah sir i have pic16f877a development board,may i use for pic18f4431 controller at same 20mhz pls help me sir,
deenadayalan



Joined: 19 Oct 2013
Posts: 19
Location: salam

View user's profile Send private message

PostPosted: Wed Sep 03, 2014 11:50 pm     Reply with quote

pls help me sir
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 04, 2014 1:09 am     Reply with quote

You want to know if you can run a 16F877A at 20 MHz on your Dev board ?

Yes, you can do it.
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