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

PIN_A7 at 5V but reading zero

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



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

PIN_A7 at 5V but reading zero
PostPosted: Sat Jun 10, 2017 1:50 am     Reply with quote

Saturday morning headaches:
I have 3 pushbuttons connected to A7, A6 and C0 with 10 kohm pull-up resisotrs.
The program should show on the LCD screen which button is pressed.
The problem is that the LCD shows the text "up" also when the button "up" is not pressed.
PIN_A7 (button "up") is at 5V as I measured with a multimeter on the pin, but the uC sees it low. What is wrong in my program?

Compiler: 5.034 PCWH
PIC16F1788 datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/40001675C.pdf

Code:
#include <16f1788.h>
#fuses NOWDT,NOPROTECT,NOBROWNOUT,NOLVP // configura fuses
//#device ICD = TRUE
#use delay(clock=8M)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
#include <i2c_Flex_LCD.h>

void main()
{
   setup_oscillator(OSC_8MHZ);
   lcd_init();
   delay_ms(20);
   lcd_clear();
   printf(LCD_PUTC,"\1 * test * ");
   delay_ms(1000);
   
   while(TRUE)
   {
    lcd_clear();
    delay_ms(20);
    if(!input(PIN_A7)) printf(LCD_PUTC,"\1 up"); //<-problem!
    if(!input(PIN_A6)) printf(LCD_PUTC,"\2 down");   
    if(!input(PIN_C0)) printf(LCD_PUTC,"\3 ok");
    delay_ms(200);
   }
}


Earlier I was using the internal pull-ups, but the uC was having strange behaviour when I was gettign my fingers close to the uC or close to the pushbuttons and their PCB tracks. Then I installed the 3x10k and solved that.

I am using the internal oscillator.
webgiorgio



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

PostPosted: Sat Jun 10, 2017 3:31 am     Reply with quote

I've found the answer! Very Happy
Code:
#fuses INTRC_IO

Quote:
It makes the crystal oscillator pins into normal i/o pins. This should fix RA6 and RA7.

From https://ccsinfo.com/forum/viewtopic.php?t=51228&start=0

Well, where can I learn what each fuse exacly does?
Code:
//////// Fuses: LP,XT,HS,RC,INTRC_IO,ECL,ECM,ECH,NOWDT,WDT_SW,WDT_NOSL,WDT
//////// Fuses: PUT,NOPUT,NOMCLR,MCLR,PROTECT,NOPROTECT,CPD,NOCPD,NOBROWNOUT
//////// Fuses: BROWNOUT_SW,BROWNOUT_NOSL,BROWNOUT,CLKOUT,NOCLKOUT,NOIESO
//////// Fuses: IESO,NOFCMEN,FCMEN,WRT,WRT_1000,WRT_200,NOWRT,VCAP,NOVCAP
//////// Fuses: PLL_SW,PLL,NOSTVREN,STVREN,BORV25,BORV19,LPBOR,NOLPBOR,DEBUG
//////// Fuses: NODEBUG,NOLVP,LVP


Last edited by webgiorgio on Sat Jun 10, 2017 10:42 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 10, 2017 4:46 am     Reply with quote

The best place to read about the fuses is the PIC datasheet.
Yes, I know almost 500 pages of dull, dreary reading BUT reading is knowledge !!
Fuses are 'blown' to setup the basic hardware configuration of the PIC. About a 1/4 of them control the 'clock' of your PIC, so reading the 'clock' chapter is crucial in 'getting it right'. At the end of each chapter, there's a table of PIC registers used and the bits used for that 'peripheral' or section of the PIC.
The other place to look is the CCS compiler's 'device header'. It will list the 'options' available for that PIC.
All PICs 'share' a LOT of common technology, so once you understand one, the rest are easy( well, easier.....)
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Jun 10, 2017 7:12 am     Reply with quote

Other important place is 'fuses.txt' with the compiler.

This gives the CCS names, and tells you what they actually correspond to.
webgiorgio



Joined: 02 Oct 2009
Posts: 123
Location: Denmark

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 2:18 am     Reply with quote

In fact a problem I always have is "translate" what I read in the data-sheet (configuration bits...) into CCS C syntax which I find in the 'device header'. That fuses.txt file helps
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 6:25 am     Reply with quote

Yes. Sometimes it is indispensable for this. Smile
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