Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
The method you have listed there sounds correct to me. Let us know if you have any success. (btw technically we would say the address flag bit is the 9th bit. This can be confusing because you would also say it is bit 8 because we call the first bit: bit 0.)
As far as bit number going if I see something like 5th 8th 9th or whatever it's a counting system, so in this case it would be the 9th bit as 0th is not something that makes sense in the English language. In common language 0 isn't really considered a number it's more of a placeholder. Ask 100 people to count to 10, I doubt any of them will start with 0.* Master will transmit slave address, make 8th bit high to make this an address byte.
LIST P=16F628A
;
#include "P16F628A.INC"
;
__config _BOREN_ON & _CP_OFF & _PWRTE_OFF & _WDT_OFF & _LVP_OFF & _MCLRE_OFF & _INTOSC_OSC_NOCLKOUT
;
CBLOCK 0x20
addre ;PIC Address
ENDC
;
ORG 0x000
;
movlw 0x07
movwf CMCON ;Turn Comparators Off
movlw 0x61
movwf addre ;Address set at 127
;
; CONFIGURE USART
;
bsf STATUS,RP0 ;Select Bank 1
;
movlw b'00000110'
movwf TRISB ;Set bits <2:1> in TRISB [pg73]
;
movlw 0x19
movwf SPBRG ;9600 baud, 1 stop bit, no parity bit w/ 4MHz Int. Osc.
;
movlw b'00100100'
movwf TXSTA ;Configure Tx for Highspeed Asynchrounous comms.
bcf STATUS,RP0 ;Select Bank 0
movlw b'11011001'
movwf RCSTA ;Configure 9-bit reception with address enable
;
; MAIN PROGRAM
;
loop call address
call receive
movwf TXREG ;Echo back byte
bsf RCSTA,ADEN ;Re-enable address detection
goto loop
;
; ADDRESS SUBROUTINE
;
address btfss PIR1,RCIF
goto address
movf RCREG,W
subwf addre,W ;Subtract addre from W
btfss STATUS,Z ;If z bit is set then the result was zero. Address match.
goto address
return
;
; Rx SUBROUTINE
;
receive bcf RCSTA,ADEN ;Clear the ADEN bit
bcf PIR1,RCIF ;Clear RCIF bit
btfss PIR1,RCIF ;WAit to receive byte
goto receive
movf RCREG,W ;Move RCREG to W
return
END