1 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
3 include /usr/share/gputils/header/p18f458.inc
7 include ../iwjpictest/clockvaries.inc
14 goto initialise_serial
16 ; interrupt routine call - this needs to be at 000018h (low priority interrupt)
26 ; globally enable interrupts - p77
27 bsf RCON,7,0 ; enable priority levels
28 bsf INTCON,7,0 ; enable high-priority interrupts
29 bsf INTCON,6,0 ; enable low-priority interrupts
31 ; initial config - TXSTA register p181
32 bcf TXSTA,6,0 ; p181, set 8-bit mode
33 bsf TXSTA,5,0 ; transmit enable
34 bcf TXSTA,4,0 ; asynchronous mode
35 bsc_txsta_brgh ; set high or low baud rate
37 ; initial config - RCSTA register p182
38 bsf RCSTA,7,0 ; serial port enable (p182)
39 bsf RCSTA,6,0 ; 8-bit reception
40 bsf RCSTA,4,0 ; enable continuous receive
42 ; set SPBRG to get correct baud rate
45 ; interrupt set-up for serial receive
46 bsf PIE1,5,0 ; enable USART receive interrupt (p85)
47 bsf IPR1,5,0 ; set to low-priority interrupt
50 ; LED pin (21) initialisation
51 bcf TRISE,4,0 ; turn off PSPMODE (Data Sheet p100/101)
54 ; timer0 initial config
55 morse_t0setup mclock, (1<<TMR0ON), -1, -1
66 bcf INTCON,2,0 ; clear timer0 interrupt bit (p109)
67 clrf TMR0H,0 ; p107 set high bit of timer0 to 0 (buffered,
68 ; so only actually set when write to tmr0l occurs)
69 clrf TMR0L,0 ; set low bit o timer0 - timer now set to 0000h
71 btfss INTCON,2,0 ; check whethr tiomer0 interrupt has been set -
72 ; skip next instruction if so
80 btfss PIR1,5,0 ; check whether serial receive interrupt bit set
81 retfie ; return from interrupt to main if spurious interrupt
83 clrf WREG ; clear working register
84 movff RCREG,WREG ; read data out of serial receive buffer -> WREG
85 incf WREG ; increment WREG
86 movff WREG,TXREG ; write data out of WREG -> serial transmit buffer