PBP migration from 16F88 to 16F1827


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hello Darrel,

    I have some more weirdness going on. I got my code to work, but not the way I want it to.

    When I read PortB using LatB, I can't seem to detect a set bit on B1. When I write directly to the
    variable in my case statement I can step through the values and the outputs are correct. I can't
    what is wrong with what I have. Code below.

    ASM
    __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _LVP_OFF & _STVREN_OFF

    ENDASM

    DEFINE OSC 8



    ;************************************************* ******************************
    ;************************************************* ******************************
    ; System hardware configuration
    ;************************************************* ******************************
    ;************************************************* ******************************

    OSCCON = %01110000 ' 8MHz internal
    ANSELA = %00000000 ' all digital. A/D disabled
    ANSELB = %00000000
    TRISB = %00111111 ' set port directions 0 = output, 1 = input
    TRISA = %00000000

    Servo1 var byte
    Servo2 var byte


    srv2 VAR LATA.1
    srv1 VAR LATA.0
    PrtB VAR LATB

    Program_init:
    PortA = 0
    POrtB = 0


    Main_Loop:



    Servo1 = PrtB and %00000111
    gosub Servo_update1

    Servo2 = PrtB and %00111000
    gosub servo_update2

    pause 10

    goto main_loop


    Servo_update1:

    select case Servo1
    case 0
    srv1 = 1 : pauseus 1000 : srv1 = 0

    CASE 1
    srv1 = 1 : pauseus 1143 : srv1 = 0

    case 2
    srv1 = 1 : pauseus 1286 : srv1 = 0

    case 3
    srv1 = 1 : pauseus 1429 : srv1 = 0

    CASE 4
    srv1 = 1 : pauseus 1572 : srv1 = 0

    case 5
    srv1 = 1 : pauseus 1715 : srv1 = 0

    Case 6
    srv1 = 1 : pauseus 1858 : srv1 = 0

    Case 7
    srv1 = 1 : pauseus 2000 : srv1 = 0

    END SELECT

    return


    Servo_update2:

    select case Servo2
    case 0
    srv2 = 1 : pauseus 1000 : srv2 = 0

    CASE 8
    srv2 = 1 : pauseus 1143 : srv2 = 0

    case 16
    srv2 = 1 : pauseus 1286 : srv2 = 0

    case 24
    srv2 = 1 : pauseus 1429 : srv2 = 0

    CASE 32
    srv2 = 1 : pauseus 1572 : srv2 = 0

    case 40
    srv2 = 1 : pauseus 1715 : srv2 = 0

    Case 48
    srv2 = 1 : pauseus 1858 : srv2 = 0

    Case 56
    srv2 = 1 : pauseus 2000 : srv2 = 0

    END SELECT

    return

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Macgman2000 View Post
    When I read PortB using LatB, I can't seem to detect a set bit on B1.
    The LATx registers only control the Output state of the pins.
    When you Read LATx, you are reading the requested Output state.

    If the pin is in Input mode, you need to read PORTx to see the state of the PIN.
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    When I switch to portB instead of LATB to read, I get nothing from my code.

    BTW I have 20K pull downs and dip switches tied to +vcc to switch in the bit pattern. There should
    be NO case when the output is nothing....even if pullups or pulldowns are messed up.

    Nick

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >Servo1 = PrtB and %00000111

    Try it with a bitwise & instead of a logical AND.
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    You are absolutely correct !!! Thanks for the fresh pair of eyes
    Nick

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, 16F1827, FSR, and Error 113
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 13th January 2014, 09:04
  3. Can PBP & 16f88 really do 9600,8,E,1
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 38
    Last Post: - 7th November 2010, 12:12
  4. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  5. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts