pins in arrays?


Results 1 to 17 of 17

Thread: pins in arrays?

Threaded View

  1. #17
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Wink

    I connected 4 buttons to PORTA's first four pin and also I connected 8 leds to PORTB and a buzzer PORTD 2. pin. You know that PIC16F877's PORTA comes in a analog mode so I used ADCON1=7 and I turned them to digital mode. (If you use PORTA and you do not use ADCON1=7, the code won't work. I tried and I saw that.)

    Then, I used this code and it worked, Thanks everybody...


    Code:
    MY CODE:
    
    '---> PORT DECLARATIONS
    TRISB = %00000000   ' Make Port B's all pins output
    OUTPUT PORTD.2       ' Make Port D's 2. pin output   
    TRISA = %00001111   ' Make Port A's 0-4 pins input
    PORTB = 0                ' Make Port B's all pins 0 Volt
    PORTD.2 = 0             ' Make Port D's 2. pin 0 Volt  
    
    '---> MAIN CODE
    counter VAR BYTE  ' Counter for different sounds.
    PortBPin VAR BYTE ' This is for turning on leds sequential order.
    
    'Any PICmicro MCU with analog inputs, such as the PIC16C7xx,
    'PIC16F87x and PIC12C67x series devices, will come up in analog mode.
    'You must set them to digital if that is how you intend to use them:
    ADCON1 = 7 
    
    loop:   'Our main loop
    
    ' For Button T0
    IF PORTA.0 = 0 THEN  ' If button T0 is pressed then generate different sounds. Counter increment rate is 10.
       FOR counter=10 to 130 STEP 10
          SOUND PORTD.2, [counter,10,60,10]  ' Generate Sound
       NEXT counter
    ENDIF
    
    ' For Button T1
    IF PORTA.1 = 0 THEN  ' If button T1 is pressed then turn on leds 0 to 7
       PORTD.2 = 0           ' Make Port D's 2. pin 0 Volt  
       FOR PortBPin=0 to 7 STEP 1
          HIGH PortBPin
          PAUSE 200
          LOW PortBPin
       NEXT PortBPin
    ENDIF
    
    ' For Button T2
    IF PORTA.2 = 0 THEN  ' If button T1 is pressed then turn on leds 7 to 0
       PORTD.2 = 0         ' Make Port D's 2. pin 0 Volt  
       FOR PortBPin=7 to 0 STEP -1
          HIGH PortBPin
          PAUSE 200
          LOW PortBPin
       NEXT PortBPin
    ENDIF
    
    ' For Button T3
    IF PORTA.3 = 0 THEN      ' If button T3 is pressed then turn on leds inside to outside then outside to inside.
       PORTD.2 = 0           ' Make Port D's 2. pin 0 Volt  (Buzzer'ı kapatır.)
       PORTB = %00011000     ' Port B's middle 4. and 5. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00100100     ' Port B's middle 3. and 6. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %01000010     ' Port B's middle 2. and 7. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %10000001     ' Port B's middle 1. and 8. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %01000010     ' Port B's middle 2. and 7. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00100100     ' Port B's middle 3. and 6. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00011000     ' Port B's middle 4. and 5. pins are turns on.
       PAUSE 300             ' Wait 300 ms
    ENDIF
    
    GOTO loop  ' Do it forever
    END ' End of our program.
    Last edited by Darrel Taylor; - 17th September 2005 at 21:04. Reason: added [code][/code] tags

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. PIC - 8 Pins - 6 Output Pins ?
    By DanPBP in forum Off Topic
    Replies: 0
    Last Post: - 22nd October 2007, 00:23
  4. I2C Effects on other PortA pins
    By kenmac in forum General
    Replies: 2
    Last Post: - 11th July 2005, 05:36
  5. PIC PORT 'special' pins
    By barkerben in forum General
    Replies: 1
    Last Post: - 18th January 2005, 21:40

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