A unit
It is some kind of a unit to which I send a clock signal with 51 microseconds delay then read a bit 5 microseconds after sending the signal. The first bit has its own pin. However, the guy says that, although I tested it in the simulator and it generates the signal, it does not work!
So, PLEASE HELP!
I am sending the signal pulses over rb2 and rb3, is that the problem?
I am sending them by putting the 00000100 or 00001000 in wreg and movwf PORTB.
I am also using the rb0 and rb1 for input, rb0 for edge interrupt.
I just don't know what is wrong...
The portb is polled for a low signal on the rb1 which takes us to start.
I am creating the timing by counting off instruction times (1 microsecond per instruction)
Maybe I should disable the pullups on portb? Maybe that is why it doesn't send signals?
Please see my init code, perhaps I made an error there?
In the simulator I see rb2 and rb3 pins going on and off, yet the guy who tests it gets nothing...
Here is the code for the start sequence which should generate the pulses:
Code:
;=============================================================================
; *--------* *----------------* *---------*
; | 0|-----|ra0 ra6|------|data |
; | |-----|ra1 | | |
; | PC |-----|ra2 PIC 16F627A | | |
; | |-----|ra3 | | |
; | |-----|ra4 | | |
; | |-----| RB5! | | |
; | |-----| RB6 | | |
; | 7|-----|ra7 | | |
; | | | | 5V | |
; | Start|-----|rb1 rb2|--*10V| |
; | Read|-----|rb0 | | | |
; | | | rb3|------|clock |
; *--------* *----------------* *---------*
list p=16f627A
#include <p16f627A.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _LVP_OFF
errorlevel -302
#define bank0 bcf 3,5
#define bank1 bsf 3,5
#define startbit1 movwf PORTB ; bit 1 clock signal start
#define stopbit1 movwf PORTB ; bit 1 clock signal stop
#define startbit2192 movwf PORTB
#define stopbit2192 movwf PORTB
#define readbit movf PORTA,0
;----------------------------------------------------------------------------
;Constants
;----------------------------------------------------------------------------
;Variables
CBLOCK 0x30
WREG_TEMP ;storage for WREG during interrupt
STATUS_TEMP ;storage for STATUS during interrupt
PCLATH_TEMP ;storage for PCLATH during interrupt
FSR_TEMP ;storage for FSR during interrupt
CORRECTION ; counter for the correction of frequency during start
BITCOUNT ; number of bits remaining to be read to fill up a byte
BYTECOUNT ; number of bytes read or sent
READSTART ; indicator of state of program, when in start state true
BUFFER ; this is where we rotate the bits we read into
COUNTER ; counter for delay of 5 microseconds
SIGNAL ; we copy PORTB to this register when we want to poll it
BYTE0
BYTE1
BYTE2
BYTE3
BYTE4
BYTE5
BYTE6
BYTE7
BYTE8
BYTE9
BYTE10
BYTE11
BYTE12
BYTE13
BYTE14
BYTE15
BYTE16
BYTE17
BYTE18
BYTE19
BYTE20
BYTE21
BYTE22
BYTE23
ENDC
;----------------------------------------------------------------------------
;This code executes when a reset occurs.
ResetCode: clrf PCLATH
goto Main
ORG 0x0004
goto InterruptCode
Main:
bank0
clrf PORTA
movlw 0x07 ;Turn comparators off and
movwf CMCON ;enable pins for I/O
clrf T1CON
clrf PORTB
bank1
movlw b'01000000'
movwf TRISA ; configure port a for output and pin 6 for input
movlw b'00000011'
movwf TRISB ; configure port b pins 0 and 1 for input
clrf OPTION_REG ; interrupt on falling edge
bank0
clrf READSTART
clrf BUFFER
clrf BYTECOUNT
clrf PIR1
clrf PIE1
clrf SIGNAL
movlw b'10010000'
movwf INTCON ; enable interrupt rb0
clrf STATUS
Signals:
movf PORTB,0
movwf SIGNAL
btfss SIGNAL,1
goto start
goto Signals
start:
clrf INTCON
clrf PORTA ; data bus = 00000000
clrf PORTB
clrf CORRECTION
movlw 8
movwf BITCOUNT
movlw .24
movwf BYTECOUNT
bit1program:
movlw b'00000100'
startbit1 ; puts ra2 to high
nop
nop
nop
nop
bcf STATUS,0
readbit ; 5.25 microseconds after clock going to high
movwf SIGNAL
btfsc SIGNAL,6
bsf STATUS,0