Shiftin pic18f452


Results 1 to 9 of 9

Threaded View

  1. #8
    Join Date
    Apr 2006
    Posts
    92


    Did you find this post helpful? Yes | No

    Default

    I was wondering if anyone could check my code here and see if there are any boo-boo's.

    I am not getting the results I have expected. I am using a 4021 shift register sending serial data out to the pic18F452.

    I have buttons connected to the 4021 (parallel to serial chip) and send the bits out to the pic. I just wanted to test it by having the pic receive a byte (%00000001) and then light up an LED.

    It worked intermittently, but not really.


    Code:
    'DEFINITIONS'
    DEFINE OSC 20
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 15
    
    'serial registers
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 31250
    
    'PORT SETUP'
    TRISA = %11111111
    ADCON1 = %10000010
    
    'VARIABLES'
    
    keys        var byte
    
    A_Button    var byte
    B_Button    var byte
    Select_Button   var byte 
    Start_Button    var byte
    Up_Button   var byte
    Down_Button var byte 
    Left_Button var byte
    Right_Button var byte
    
    
    A_Button = %00000001
    B_Button = %00000010
    Select_Button = %00000100
    Start_Button = %00001000
    Up_Button = %00010000
    Down_Button = %00100000
    Left_Button = %01000000
    Right_Button = %10000000
    
    
    ''Pin Assignments''
    data_in var portb.7 
    latch var portb.6   
    clock var portb.5
    
    main:
    
    pulsout latch, 1    'toggle the latch pin
    shiftin data_in, clock, 0, [keys] 
    
    if keys = A_Button then    'if A button pressed light LED on RB0
    high portb.0
    pause 1
    low portb.0
    endif
    
    goto main
    Last edited by TonyA; - 17th August 2009 at 21:56.

Similar Threads

  1. Shiftin question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th November 2007, 19:09
  2. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 19:54
  3. SHIFTIN problem
    By champion in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th January 2007, 03:31
  4. Using SHIFTIN
    By TonyA in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st May 2006, 15:38
  5. PIC18F458 Shiftin / Out
    By pberhin in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th May 2006, 20:36

Members who have read this thread : 0

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