Variable to ports


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Variable to ports

    here is an "exemplar" code you may glean some use of, it is for a pic16f690 demo board
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF 
    DEFINE OSC 4 
    I VAR BYTE
    LED  var byte
    TEMP var WORD
    OVERFLOW VAR WORD
    Relays  VAR BYTE : Relays = 0
    
    'DEFINE ADC_BITS 10      ' Set A/D for 8-bit operation
    'DEFINE ADC_CLOCK 3      ' Set A/D clock Fosc/8
    'DEFINE ADC_SAMPLEUS 50  ' Set A/D sampling time @ 50 uS
    
    
    temp = 0
    OVERFLOW = 0 
    serout porta.0,2, [$FE,1,"Loops ",# temp," "]
    ADCON1 = 0
    ANSEL  = 0
    portc = %00000000
    TRISC = %00000000
    ;LOW portB.7
    
    ;MyPort var byte
    main:
    
    'ADCIN 0, TEMP
    
     myPort var bit[8]
     Portc.0 = MyPort[0]  
     Portc.1 = myPort[1]  
     Portc.2 = myPort[2]  
     Portc.3 = myPort[3]  
     Porta.1 = myPort[4]  
     Porta.2 = myPort[5]   
     Porta.3 = myPort[6]   
     PortB.7 = myPort[7]  
    'random temp 
     'myPort = %00000000
     TrisA = %00000000
     TrisB = %00000000
     Trisc = %00000000
    'FOR led = 0 to 4 + 1 
    
    
    pattern var byte
    index var byte
    'Pattern = %11111111
    
    'Pattern = %00001111
    FOR index = 0 to 19
    ;MYpORT = MYpORT + 1
    LOOKUP index,[%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000101,%11111010,%00000101,%11111010,%00001001,%00000110,%11111111,%11111001,%11111111], pattern
        'pattern = (pattern >>1)
       portc = ~~Pattern   'turn portb.0 on or off based on whether the bit is 0 or 1
     ;Portc.0 = MyPort[0]  
     ;Portc.1 = myPort[1]  
     ;Portc.2 = myPort[2]  
     ;Portc.3 = myPort[3]  
     ;Porta.1 = myPort[4]  
     ;Porta.2 = myPort[5]   
     ;Porta.3 = myPort[6]   
     ;PortB.7 = myPort[7]  
        ;2 bitwise NOTS 1st not changes T/F to Pattern and second inverts value
        ;PORTC = Pattern is a T/F statement the ( ! ) changes it to ENGLISH :D
        PAUSE 300
    NEXT index
    
    temp = temp + 1
    
    
    serout porta.0,2, ["Loop ",# temp," "]
    IF TEMP >= 65535 THEN
    OVERFLOW = OVERFLOW + 1
    IF OVERFLOW >=1 THEN SEROUT PORTA.0,2,["OVERFLOW ",#OVERFLOW," "]
    PAUSE 5000
    ENDIF
    'TEMP = TEMP / 5
    'pause temp MAX 2
    'portc = portc << 1  
    
    'TRISC = I
    'next led
    
    
    'FOR led = 0 to 3 + 1
    'pause temp
    'portc = portc >> 1
       
    'next led
    
    goto main
    
    end
    The code listed above has lots of unimportant stuff in it as I use it to test snippits the important part is portc = ~~Pattern 'turn portb.0 on or off based on whether the bit is 0 or 1
    Last edited by Archangel; - 11th April 2013 at 22:41.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Adding Ports status to a variable
    By lilimike in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th March 2013, 23:05
  2. Need two SDA SCL ports
    By lerameur in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th November 2010, 17:43
  3. activating i/o ports according to variable value
    By Picman in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th July 2010, 14:55
  4. accessing ports pins using an index variable
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th March 2008, 21:36
  5. One variable made up of another variable
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st September 2007, 01:18

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