PDA

View Full Version : Digital output (RA5) on 16f884



andybarrett1
- 16th May 2017, 10:47
Help......

Hi Thank you for reading..... I am attempting to output 16 Leds on ports A and C using a 16F884

All is working ok but for RA5 (Pin7)..... I suspect I have not turned of an analogue function but what one..

Any help welcome..... all code is working fine but for this pin.... It just stays high all time !

See my headers below.

Thank you for reading

Andy





'__config _CONFIG1,
'_INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF &_CDP_OFF

'__config _CONFIG2, _WRT_OFF & _BOR40V

'Port A Leds
'Port B Buttons with Internal Pullups
'Port C Leds
'Port D Display

' LCD should be connected as follows:
' LCD PIC
' DB4 PortD.0
' DB5 PortD.1
' DB6 PortD.2
' DB7 PortD.3
' RS PortD.4
' E PortD.5
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 50K potentiometer (or ground)
' DB0-3 No connect

OSCCON = $70 'Sets internal Osc at 8Megs

ANSEL=0 'Turn off Analogs
ANSELH=0
ADCON0=0
ADCON1=0
CM1CON0=0
CM2CON0=0
CM2CON1=0
CCP1CON=0
CCP2CON=0

OPTION_REG.7=0 'Port B Pullups active

TRISA=0 'PORT A Outputs
TRISB=15 'PORT B Inputs
TRISC=0 'PORT C Outputs

DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCDLINES 2


LED0 VAR PORTA.0
LED1 VAR PORTA.1
LED2 VAR PORTA.2
LED3 VAR PORTA.3
LED4 VAR PORTA.4
LED5 VAR PORTA.5
LED6 VAR PORTA.6
LED7 VAR PORTA.7

BUT0 VAR PORTB.0
BUT1 VAR PORTB.1
BUT2 VAR PORTB.2
BUT3 VAR PORTB.3
BUT4 VAR PORTB.4
BUT5 VAR PORTB.5
BUT6 VAR PORTB.6
BUT7 VAR PORTB.7

LED8 VAR PORTC.0
LED9 VAR PORTC.1
LED10 VAR PORTC.2
LED11 VAR PORTC.3
LED12 VAR PORTC.4
LED13 VAR PORTC.5
LED14 VAR PORTC.6
LED15 VAR PORTC.7

andybarrett1
- 16th May 2017, 12:46
Hi All

Looked at this a little bit further..... I now believe it is RB5/AN13/T1G Causing me the issue.

Maybe the T1G Timer ??

How do I disable this and make the port just a DI

Many thanks

Andy

tumbleweed
- 16th May 2017, 14:16
TRISB = 15

You're only setting RB0-RB3 as inputs

Dave
- 16th May 2017, 14:29
Andy, Make sure CM2CON1 is set to all zero's.

CM2CON1 = %00000000
This register defaults to T1GSS to T1G enabled at power on. I don't however believe that is the problem.

andybarrett1
- 16th May 2017, 15:18
TRISB = 15

You're only setting RB0-RB3 as inputs

Thanks both for help..... Missing the obvious, for some reason I copied and pasted previous code, but left TRISB as 15.

Changed to 255 and all works now......:biggrin:

Thank you again

Samoele
- 17th May 2017, 11:18
You have porta set to output try with resistor 4K7 between RA5 and VCC.

Demon
- 17th May 2017, 20:18
Just a tip for visual people like me:

- use individual bits for fuses, it's much easier to determine which bit is ON or OFF.

For example:
TRISB=%00001111
versus
TRISB=$0F
versus
TRISB=15

Robert
:)

andybarrett1
- 18th May 2017, 14:52
Just a tip for visual people like me:

- use individual bits for fuses, it's much easier to determine which bit is ON or OFF.

For example:
TRISB=%00001111
versus
TRISB=$0F
versus
TRISB=15

Robert
:)

Very good advice.... My problem is disciplining myself to carry it out.

Maybe I need slow down a bit :-)

BR
Andy