|
|
View previous topic :: View next topic |
Author |
Message |
steve_smith94
Joined: 21 Mar 2011 Posts: 7 Location: London
|
How to configure IOC on PIC16F917 |
Posted: Mon Mar 21, 2011 5:22 am |
|
|
Hi,
I'm a PIC newbie and have been given a circuit and asked to write the software.
I need to recognise a High (5v) on either RB6 and RB7, provided by a momentary push button switch. Then run code dependant upon which button is switch.
I have tried all the examples i can find on configuring the interrupts and can't seem to get it to work.
One obvious problem is that I'm unable to use pullups on port B as I need to trigger on a high.
Any pointers would be most welcome. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Mar 21, 2011 6:03 am |
|
|
Without seeing the code you wrote it's very hard to tell you what's wrong !
Could be your hardware setup, could be software...
Wrong or missing pulldown resistors, power supply incorrect,defective switches, bad wiring, just to start...
Sounds like you want a low-to-high interrupt. you will need debouncing on the pushbuttons.
The example that CCS supplies will work,the help file has an FAQ section. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 21, 2011 1:18 pm |
|
|
Quote: | One obvious problem is that I'm unable to use pullups on port B as I need
to trigger on a high. |
But you control the source code. You can use positive logic or negative
logic. The C language is completely flexible with respect to that.
Here is the normal way to connect a push-button switch to a PIC:
Code: |
+5v
|
<
> 4.7K
< ___ Push button switch
To | _|_|_
PIC -----------------o o------
pin |
--- GND
-
|
However, sometimes on PIC hobby websites, you will see it wired the
opposite way. When you press the switch, it connects the +5v Vdd voltage
to the PIC pin. I suspect you are looking at one of those websites.
This thread has links to several push-button switch example programs:
http://www.ccsinfo.com/forum/viewtopic.php?t=42285 |
|
|
steve_smith94
Joined: 21 Mar 2011 Posts: 7 Location: London
|
|
Posted: Tue Mar 22, 2011 3:42 am |
|
|
Thanks guys.
\My code is below
Code: |
#include <16F917.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NODEBUG //No Debug mode for ICD
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=20000000)
#include "C:\Documents and Settings\Smiths\Desktop\test\test1.h"
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
short int dbutton6, dbutton7;
#int_RB
void RB_isr(void)
{
int current;
static int last=0;
set_tris_b(0xF0);
current=input_b();
if ((!bit_test(last,6))&&(bit_test(current,6)))
{
//b6 went High
dbutton6=1;
}
if ((!bit_test(last,7))&&(bit_test(current,7)))
{
//b7 went High
dbutton7=1;
}
delay_ms(10);
}
void clear_delta()
{
dbutton6=0;
dbutton7=0;
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_lcd(LCD_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
clear_delta();
while(1)
{
output_bit(PIN_D0,0);
output_bit(PIN_D1,0);
output_bit(PIN_D2,0);
output_bit(PIN_D3,1);
output_bit(PIN_D4,0);
output_bit(PIN_D5,0);
output_bit(PIN_D6,0);
output_bit(PIN_D7,1);
delay_ms( 1000 ) ;
if(dbutton6)
{
output_bit(PIN_D0,1);
output_bit(PIN_D1,1);
output_bit(PIN_D2,0);
output_bit(PIN_D3,0);
output_bit(PIN_D4,1);
output_bit(PIN_D5,1);
output_bit(PIN_D6,0);
output_bit(PIN_D7,0);
//dbutton6=0;
delay_ms( 1000 ) ;
}
if(dbutton7)
{
output_bit(PIN_D0,0);
output_bit(PIN_D1,1);
output_bit(PIN_D2,1);
output_bit(PIN_D3,0);
output_bit(PIN_D4,0);
output_bit(PIN_D5,1);
output_bit(PIN_D6,1);
output_bit(PIN_D7,0);
//dbutton7=0;
delay_ms( 1000 ) ;
}
}
}
|
All that happens is two 7 seg displays output figures dependant upon which switch is depressed( RB6 or RB7). Unfortunatly the hardware switches +5v
There are no pull down resistors on the inputs. However, scoping the pind RB6 and RB7 the levels look good. But I will try to place some pull downs on the lines and report back with my findings.
Cheers |
|
|
steve_smith94
Joined: 21 Mar 2011 Posts: 7 Location: London
|
|
Posted: Tue Mar 22, 2011 3:45 am |
|
|
Just one further question; what size pull downs would you suggest? 4k7 as per pull ups? |
|
|
steve_smith94
Joined: 21 Mar 2011 Posts: 7 Location: London
|
|
Posted: Wed Mar 23, 2011 9:20 am |
|
|
I have downloaded the real pic simulator to aid my getting to the bottom of this issue.
Using this configured for a PIC16F917, I can't get any of the examples I have seen to work.
Is there a ccs compiling issue for this PIC?
Does anyone have any ideas how I can get an int_rb interrupt to work with this PIC? I have now pulled down my 2 ports using a 10k res (still no joy). But seeing the simulator also doesn't work I guess that it must be a software issue.
Please help |
|
|
|
|
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
|