Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ports not doing whats told to them

Status
Not open for further replies.

MrDEB

Well-Known Member
Benn hacking at this code for several days but still can't get portb.6 and 7 to work correctly.
Tried chanhing the toggle routing (PRESS or PRESS2) all i does is turns on two different leds.
thinking a short but no.
using PRESS() LED 6 & 7 are ON. using PRESS2() LED1 & 2 are ON. both without a button press.
code is using SWORDFISH
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/10/2022                                                      *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 2/9/2022                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F43k22 ' Tell the compiler what chip we are using
Clock = 8 ' Tell the compiler what we will be setting the clock to (Mhz)

#OPTION DIGITALLIO_INIT=TRUE
Include "SetDigitalIO.bas"       // Include this file when we compile so that we can use keywords like 'setalldigital'
Include "utils.bas"
Include "convert.bas"
Include "intosc.bas"

Dim y As Byte
Dim x As Byte
Dim Player As Byte
Dim counter As Byte
Dim Switch As PORTE.1


//PLAYER LEDS
Dim led1 As PORTA.0
Dim led2 As PORTA.1
Dim led3 As PORTA.2
Dim led4 As PORTA.3
Dim led5 As PORTA.4
Dim led6 As PORTA.5
Dim led7 As PORTA.6
Dim led8 As PORTA.7

//player buttons
Dim Button0 As PORTB.0
Dim Button1 As PORTB.1
Dim Button2 As PORTB.2
Dim Button3 As PORTB.3
Dim Button4 As PORTB.4
Dim Button5 As PORTB.5
Dim Button6 As PORTB.6
Dim Button7 As PORTB.7

Dim Battery As PORTA.2  'hlvd
Dim Power As PORTA.1     'hlvd

SUB PRESS()
if button0 = 0 then toggle (led1) end if
if button1 = 0 then toggle (led2) end if
if button2 = 0 then toggle (led3) end if
if button3 = 0 then toggle (led4) end if
if button4 = 0 then toggle (led5) end if
if button5 = 0 then toggle (led6) end if
if button6 = 0 then toggle (led7) end if
if button7 = 0 then toggle (led8) end if
end sub                     
                    
SUB PRESS2()
if button0 = 0 then toggle (led1) end if
if button1 = 0 then toggle (led2) end if
if button2 = 0 then toggle (led3) end if
if button3 = 0 then toggle (led4) end if
if button4 = 0 then toggle (led5) end if
if button5 = 0 then toggle (led6) end if
if button6 = 0 then toggle (led1) end if
if button7 = 0 then toggle (led2) end if
end sub                     
                                        
                    
                    
                    
  Sub Player_Press()
 Select(Player)                             
        Case 1 Button0=0 Toggle(led1)
        Case 2 Button1=0 Toggle(led2)
        Case 3 Button2=0 Toggle(led3)
        Case 4 Button3=0 Toggle(led4)
        Case 5 Button4=0 Toggle(led5)
        Case 6 Button5=0 Toggle(led6)
        Case 7 Button6=0 Toggle(led7)
        Case 8 Button7=0 Toggle(led8)
 End Select
End Sub


SETALlDigital                       // Make all Pins digital I/O's
TRISA=0
'TRISC = 0               // LED port - all outputs
'TRISD=0
TRISB = $FF             // SW port - all inputs
WPUB = $FF              // PORTB pullup mask - all PORTB pullups
INTCON2.bits(7) = 0     // RBPU bit - turn on pullups

              
'TRISC = %00000000              // Make PORTC all outputs COLUMS ON MATRIX   
'TRISA = %00000000              //PLAYER LEDS
'TRISD = %00000000              //MATRIX ROWS
x = 0
y = 0
'Switch = 1

Input (Switch)           // counter button
'Switch = 1

//PLAYER LEDS  PORTA
Output (led1)
Output (led2)
Output (led3)
Output (led4)
Output (led5)
Output (led6)
Output (led7)
Output (led8)
{
//PLAYER INPUT BUTTONS
Input(Button0)
Input(Button1)
Input(Button2)
Input(Button3)
Input(Button4)
Input(Button5)
Input(Button6)
Input(Button7)
}


//HLVD
Output (Battery)
Output (Power)

led1 =0
led2 =0
led3 =0
led4 =0
led5 =0
led6 =0
led7 =0
led8 =0
Input(Switch)     //PORTE.1
counter = 12
Player=0

While true
 press2()


'TEST()
 ' Player_Press()
  Wend
 
???????
deb.png
 
yes pickit2 is connected.
As I mentined IF I run the board with only sub PRESS() then LED7 and LED8 come ON.
If I run the board with only PRESS2() then LED1 and LED2 come ON.
No I only run one of the subroutines. I wrote PRESS2() to verify if I had a short or?
If there was a short then subroute PRESS() or PRESS2() shouldn't make a difference.
I hope this clarifys what the board is doing.
Its my understand that B6 and B7 are only enabled when programming and when done loading the code only Vcc and GRD are enabled. Having the pickit2 connected shouldn't affect it?
 
IF the pickit2 is still connected then why does the subroute PRESS() ans PRESS2() MAKE A DIFFERENCE??
Just asking.
 
portb.6 and 7 ah yes, that brings back memories of checking cmcon and some other registers associated with those pins
 
IF the pickit2 is still connected then why...
The pickit2 has 4.7K pulldown resistors on the PGC and PGD pins, so that's going to make the RB6 and RB7 pins look like a logic low with no button pressed even though you have the internal pullups enabled.

To be seen as a logic high, the internal pullups would have to be a very low R value in order to combine with the voltage divider that gets created when the pickit2 is attached.

All of the ICSP programmers have these, although on some they're programmable.
You'll have to remove the pickit after you program the chip for those two buttons to work.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top