PIC16F684 Part 010 - Optimizing Code and RRF Instruction

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 3

  • @2bit661
    @2bit661  4 месяца назад

    ;free sample code. copy and paste.
    processor 16F684
    include "p16f684.inc"
    ; Configuration settings
    __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF
    R1 EQU 0x20 ; outer loop counter
    R2 EQU 0x21 ; inner loop counter
    C1 EQU 0x22 ; specify file to store counter value
    BIT_COUNTER EQU 0x23 ; counter for bit testing
    ; Define connections
    #define SER_IN PORTA, 0 ; RA0 connected to 74HC595 SER_IN
    #define L_Clock PORTA, 1 ; RA1 connected to 74HC595 L_Clock
    #define Clock PORTA, 2 ; RA2 connected to 74HC595 Clock
    ; Main program start
    org 0x0000
    goto Initialize
    ; Main program
    Initialize:
    ; Initialize ports
    bsf STATUS, RP0 ; Switch to Bank 1
    clrf ANSEL ; Set all pins to digital
    clrf TRISA ; Set all pins of PORTA as output
    bcf STATUS, RP0 ; Switch to Bank 0
    LOOP:
    MOVLW B'11101010'
    MOVWF C1
    CLRF BIT_COUNTER

    BITTESTER:
    BCF SER_IN ; Clear SER_IN initially
    MOVF BIT_COUNTER, W
    BTFSC C1, 0
    BSF SER_IN ; Set SER_IN if the corresponding bit in C1 is 1
    CALL DELAY
    CALL SHIFT_CODE

    ; Shift C1 right by 1 bit
    RRF C1, F ; rotate right f through carry
    INCF BIT_COUNTER, F
    MOVLW 8
    SUBWF BIT_COUNTER, W
    BTFSS STATUS, Z ; Check if BIT_COUNTER == 8
    GOTO BITTESTER ; Repeat until 8 bits are tested

    BSF L_Clock ; L_CLOCK (PORTA, 1) sets or latches previously-sent 8 bits
    CALL DELAY
    BCF L_Clock ; L_CLOCK cleared back to low
    CALL DELAY

    GOTO LOOP
    SHIFT_CODE: ; shift register subroutine
    BSF Clock ; Clock pin (PORTA, 2), clocks in whatever serial input (PORTA, 0) is doing
    CALL DELAY
    BCF Clock
    CALL DELAY
    BCF SER_IN
    CALL DELAY
    RETLW 0
    DELAY:
    MOVLW 0xFF
    MOVWF R1
    AGAIN:
    MOVLW 0xFF
    MOVWF R2
    HERE:
    NOP
    NOP
    DECFSZ R2, F
    GOTO HERE
    DECFSZ R1, F
    GOTO AGAIN
    RETLW 0
    END ; Needed to end the program.

  • @yuvarajcena26
    @yuvarajcena26 4 месяца назад +1

    6502 cpu

    • @2bit661
      @2bit661  4 месяца назад

      Thanks for your comment. I searched RUclips for "6502 cpu" and found this video: ruclips.net/video/acUH4lWe2NQ/видео.html
      Wow! I didn't realize such a chip was so popular and widely used.
      I am learning too. I didn't realize hobbyists can program these chips: ruclips.net/video/k1iv2ANb2Ko/видео.html
      Of course, I am using a PIC Microcontroller in my experiments. The Microchip PIC Chips are different. Maybe you knew that. The software for PIC chips is MPLAB. Thanks for your comment. Have a nice day.