-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.asm
64 lines (57 loc) · 1.04 KB
/
Code.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
list p=18F452
include <P18f452.INC>
COUNT1 EQU 0xF0
COUNT2 EQU 0xF1
COUNT3 EQU 0xF2
org 0x00
SETF TRISB
MOVLW B'10000000'
MOVWF TRISC
CLRF TRISD
ClRF TRISA
MOVLW 0xAA
MOVWF PORTA
MOVLW 0x05
MOVWF SPBRG
MOVLW 0x20
MOVWF TXSTA
MOVLW 0x90
MOVWF RCSTA
LOOP:
RCALL TRANSMIT
RCALL DELAY
RCALL RECEIVE
RCALL DELAY
goto LOOP
DELAY:;delay counters were calculated to provide a 100ms delay
MOVLW D'5' ;code kept getting stuck at delay due to an unknown reason
MOVWF COUNT1 ; setting these low values by random seemed to solve the problem (but doesn't actually generate delay) which is better than a delay that gets stuck forever
AGAIN1:
MOVLW D'1'
MOVWF COUNT2
AGAIN2:
MOVLW D'1'
MOVWF COUNT3
AGAIN3:
NOP
DECFSZ COUNT3
BRA AGAIN3
DECFSZ COUNT2
BRA AGAIN2
DECFSZ COUNT1
BRA AGAIN1
RETURN
TRANSMIT:
MOVF PORTB,W
MOVWF TXREG
TXCHECK: ;wait until byte is fully transmitted
BTFSS PIR1,4
GOTO TXCHECK
RETURN
RECEIVE:
BTFSS PIR1,5 ; make sure there is received data
RETURN
MOVF RCREG,W
MOVWF PORTD
RETURN
END