fastback86
Member
I'm working on a project that will eventually be a 3 digit counter but I have a small issue I believe is in the code I wrote. The circuit is a PIC16F676 driving 3 common anode multiplexed 7 segment displays with the anodes driven by MOSFETs. Just to test things out I wrote some code just to alternate a "1" between the ONES place and TENS place. So far that works ok but the HUNDREDS digit wants to turn on randomly. It seems the gate of the MOSFET controlling that digit is "floating" even though it is connected to pin 4 (RA3/MCLR/Vpp) of the PIC. I have put a logic probe directly on pin 4 and verified a state that's neither H nor L. Have I done something wrong in the code or is it that I just can't wire the circuit like I have it?
Sorry for the messy post, the "insert code" box doesn't work for some reason.
Code:

Sorry for the messy post, the "insert code" box doesn't work for some reason.
Code:
Code:
#include <p16f676.inc>
List P=16F676
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops
COUNT3 equ 22h ;Third counter for delay loop.
;20h, 21h, 22h, are addresses in the general register
;that are used to store a variable
Start
BSF STATUS, RP0 ; Bank 1
CLRF TRISA ; PortA all output
CLRF TRISC ; PortC all output
BCF STATUS, RP0 ; Bank 0
movlw b'00111111' ;
movwf PORTC ;set all of PORTC high turning segments off
movlw b'00101101'
movwf PORTA ;set RA5 high to turn segment g off and
;set RA0,2, and 3 H to turn digit off
Main
movlw b'00010111' ;set RA3 and RA5 low to turn on segments b and c
movwf PORTC
movlw b'00101001' ;select digit 1 (LSD)
movwf PORTA
call Delay
movlw b'00101100' ;select digit 1 (LSD)
movwf PORTA
call Delay
goto Main
Delay
movlw D'200' ;load decimal 200 into w
movwf COUNT1 ;move 200 to f then to variable COUNT1
movlw D'200' ;COUNT1=200, COUNT2=200, COUNT3=4 gives a nice flash rate
movwf COUNT2
movlw D'4'
movwf COUNT3
Loop1 decfsz COUNT1,1 ;decrement variable COUNT1 by one
goto Loop1 ;goto Loop1 if COUNT1 is not zero, skip this step if it is zero
decfsz COUNT2,1 ;next decremented counter...
goto Loop1
decfsz COUNT3,1 ;next decremented counter...
goto Loop1
return
end

Last edited: