View previous topic :: View next topic |
Author |
Message |
juinhooley
Joined: 02 Aug 2011 Posts: 10
|
Confused pin on PIC16F1946 |
Posted: Thu Aug 18, 2011 1:29 am |
|
|
Hi,
I'm using the above micro, the 64pin tqfp package.
Pin 45 is connected to a switch button.
I'm going to have an LCD display but it is not connected at the moment. I'm trying to write the program for reading switches and drive other output at the moment.
That button that is connected to pin 45 (RB3/SEG10) stop working whenever I have this line
Code: |
setup_lcd( LCD_TYPE_B | LCD_MUX13 | LCD_BIAS13 | LCD_REF_ENABLED | LCD_B_HIGH_POWER | LCD_TIMER1, 0, 0x131437); |
It works okay without this line. My fuses are
Code: |
#device ICD = TRUE
#FUSES WDT //Watch Dog Timer
#FUSES LP
#FUSES WDT_NOSL //Watch Dog Timer, disabled during SLEEP
#FUSES WRT //Program Memory Write Protected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOLVP //No low voltage prgming,
#FUSES NOMCLR
#FUSES INTRC_IO
#FUSES PUT
|
Any idea why?
Many thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 18, 2011 11:40 am |
|
|
Quote: | #device ICD = TRUE
#FUSES WDT //Watch Dog Timer
#FUSES LP
#FUSES WDT_NOSL //Watch Dog Timer, disabled during SLEEP
#FUSES WRT //Program Memory Write Protected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOLVP //No low voltage prgming,
#FUSES NOMCLR
#FUSES INTRC_IO
#FUSES PUT
|
Don't use two oscillator fuses. LP is for a watch crystal (32.768 KHz).
INTRC_IO is the internal oscillator. Delete the LP fuse. Also, don't
enable the WDT in a test program. Delete the WDT fuse.
Quote: |
Pin 45 is connected to a switch button.
I'm going to have an LCD display but it is not connected at the moment. I'm trying to write the program for reading switches and drive other output at the moment.
That button that is connected to pin 45 (RB3/SEG10) stop working whenever I have this line
setup_lcd( LCD_TYPE_B | LCD_MUX13 | LCD_BIAS13 | LCD_REF_ENABLED | LCD_B_HIGH_POWER | LCD_TIMER1, 0, 0x131437);
|
What board are you using ? Post the manufacturer and part number. |
|
|
juinhooley
Joined: 02 Aug 2011 Posts: 10
|
|
Posted: Sun Aug 21, 2011 5:18 pm |
|
|
PCM programmer wrote: |
#device ICD = TRUE
#FUSES WDT //Watch Dog Timer
#FUSES LP
#FUSES WDT_NOSL //Watch Dog Timer, disabled during SLEEP
#FUSES WRT //Program Memory Write Protected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOLVP //No low voltage prgming,
#FUSES NOMCLR
#FUSES INTRC_IO
#FUSES PUT
Don't use two oscillator fuses. LP is for a watch crystal (32.768 KHz).
INTRC_IO is the internal oscillator. Delete the LP fuse. Also, don't
enable the WDT in a test program. Delete the WDT fuse.
|
I have tried to disable LP fuse and WDT fuse. It's still the same. Has it anything to do with the LCD setup instead?
Quote: |
What board are you using ? Post the manufacturer and part number. |
It's our own board. It consists of a PIC16F1946-TQFP64 connected to a custom made LCD display, some switches and LED lights. I can send you the schematic if you give me your email address. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Aug 21, 2011 5:55 pm |
|
|
OK, it's really very simple. The number shown in bold is the segment
enable bitmask:
Quote: |
setup_lcd( LCD_TYPE_B | LCD_MUX13 | LCD_BIAS13 | LCD_REF_ENABLED | LCD_B_HIGH_POWER | LCD_TIMER1, 0, 0x131437);
|
First, convert it to binary represenation:
Code: |
Register: SE2 SE1 SE0
Value in hex: 0x13 0x14 0x37
Binary value: 0001 0011 0001 0100 0011 0111
Bit number 23.......16 15.......8 7.......0
|
|
Note bit 10
above = 1. This is the Seg10 pin.
|
This means you have Seg10 enabled as an LCD segment driver pin.
The 16F1947 data sheet says that when you do this, you can't use it
as an ordinary i/o pin:
Quote: | 27.6 Segment Enables
The LCDSEn registers are used to select the pin
function for each segment pin. The selection allows
each pin to operate as either an LCD segment driver or
as one of the pin’s alternate functions. To configure the
pin as a segment pin, the corresponding bits in the
LCDSEn registers must be set to ‘1’.
If the pin is a digital I/O, the corresponding TRIS bit
controls the data direction. Any bit set in the LCDSEn
registers overrides any bit settings in the corresponding
TRIS register.
|
So if you're not using Seg10 for your LCD, then don't set the bit for it
in the Segment Enables bitmask parameter. Change it to a zero bit. |
|
|
juinhooley
Joined: 02 Aug 2011 Posts: 10
|
|
Posted: Sun Aug 21, 2011 5:59 pm |
|
|
Good point! I copied that line from my old code and didn't think of checking that.
It works now, with the LCD segments configured correctly.
Many thanks. |
|
|
|