
Originally Posted by
Sneaky-geek
Hello all,
I hate to do this, I have to ask for help. I can't get PORT D to work properly.
Gear used:
PBP V2.50b
MCS Plus
PIC 16f877a
MELABS USB PROGRAMMER
PICPROTO 64
Program causing me toloose my sanity (what little I had):
'************************************************* ***************
'* Name : BCD True and Complimentary Switch Decoder *
'* with 7segement LED display *
'* *
'* Author : Terry L.Garrett K9HA *
'* Notice : Copyright (c) 2008 Terry L. Garrett *
'* : All Rights Reserved *
'* Date : 10/4/2008 *
'* Version : 3.0 *
'* Notes : 7 Segment LED display TEST *
'* : Correct display for 0 to F HEX *
'************************************************* ***************
'************************************************* ***************
' PURPOSE:
' Read and display BCD 4 bit bcd switches, both TRUE AND COMPLIMENTARY
'
' * * * System Defines * * *
'
'
@ DEVICE pic16f877a, CPD_OFF
@ DEVICE pic16f877a, PROTECT_OFF
@ DEVICE pic16f877a, WRT_OFF
'
DEFINE OSC 4
ADCON1=7 ' SETS PORTS AS ALL DIGITAL( I HOPE)
'
'????????????????????????????????????????????????? ????????????
'
INTCON=0 'I Think this turns off ALL INTERUPTS FOR PORTB????
'
'????????????????????????????????????????????????? ?????????????
'
'************************************************* ***************
'
' Variable Descritptions:
'
' NAME # bits location I/O Description
' Type 1 PortD0 IN LOW for TRUE
' HIGH for COMPLEMENTARY
' PortD.0 1 Program BIT VAR BIT
'
'************************************************* ***************
'
' * * * VARIABLE DECLARATIONS * * *
'
' NOTICE: bin2binary subroutine(s) are from melabs website
' Thank you, melabs
'************************************************* *****************
'
B0 var byte 'Used in subroutine to generate LED Segment data
'B1 var byte 'Used in subroutine to generate LED Segment data
Type var BIT 'PortD.0
'
'************************************************* ***************
' DEVICE SET-UP
'
CLEAR ' Is this the proper place to put this?
'
TRISB=%11111111 ' ALL 8 BITS SET AS INPUT: HOEVER ONLY LOWER 4 REALLY USED.
' ' *** GROUND BITS 4-7 ***
'
PortB=%11111111 ' ALL BIT PRELOADED TO 1. Known condition.
'
TRISC=%00000000 'ALL BITS SET AS OUTPUT ( BITS 0-6: LED SEGMENTS 1-7
'
PortC=%11111111 'ALL BITS preloaded as HIGH (LED DISPLAY IS OFF)
'
TRISE.4=%0 ' Makes Port D DIGITAL I/O?
'
TRISD=%11111111 ' Ground bits 1-7
'
PortD.0=%0 ' PORTD.0 preloaded to ZERO (LOW). Known condition
tYPE = PortD.0 ' Se
'
Main:
while Type <1
B0=PortB
gosub lowloop
wend
'
'while type = 1
'gosub Highloop
'wend
goto main ' This should cause constant reading/input from PORTB
'
'************************************************* *************************
'
LowLoop:
' B0 = B1 ' Pass the PORTB data
Gosub bin2seg ' Convert to segment value
Poke PortC, B0 ' Put segment values out to LED
Pauseus 1 ' Display it for 1 microsecond
Poke PortC,$1E ' Turns off display
pauseus 1 ' Display is OFF for 1 microsecond
return ' RETURNS to MAIN; gets next PORTB data
' ************************************************** *****
' ************* 2nd level soubroutines follow ******************
' Convert binary number in B0 to segments for LED
bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18,$88,$83,$C 6,$A1,$86,$8E],B0
Return
END
' CLEAN COMPILE 145 WORDS USED 10/04/2008 06:00:00 PM CDT
'
' * note to self: this worked until you added the PORTD code, the wend while
' argument.
'
' *!*! This don't work correctly
Where did I go wrong?
I know that a few will say RTFM, Ha Ihave and my wife says if I stay up late one more night
that I can sleep with the dogs. I DO NOT HAVE A DOG.
Bookmarks