list p=18f4685
#include <p18f4685.inc>
; PIC18F4685 @ 40Mhz 10 MIPS
; 1uS = 10 instructions
; Connected to VGA as follows
; PORTA.0 = RED
; PORTA.1 = GREEN
; PORTA.2 = BLUE
; PORTB.7 = HSync
; PORTB.6 = VSync
LineCount1 equ 0x60
LineCount2 equ 0x61
VertCount1 equ 0x62
VertCount2 equ 0x63
VertCount3 equ 0x64
Delay10TCY: macro
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
endm
Delay100TCY: macro
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
endm
org 0
goto Start
org 0x30
Start:
; set the AD pins to all digital
bcf ADCON1, PCFG3
bsf ADCON1, PCFG2
bsf ADCON1, PCFG1
bsf ADCON1, PCFG0
; set PORTA and PORTB to output
clrf TRISA
clrf TRISB
; clear PORTA and PORTB
clrf PORTA
clrf PORTB
; set the color to solid red
bsf PORTA, 0
; set the VSync and HSync bits
bsf PORTB, 7
bsf PORTB, 6
; set the line counters
setf LineCount1
movlw 0xE0
movwf LineCount2
movlw 0x0D
movwf VertCount1
movlw 0x02
movwf VertCount2
movlw 0x21
movwf VertCount3
VideoLoop:
LineCounter1Loop:
; 25.17uS display line approx 251 cycles
Delay100TCY
Delay100TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
; hsync front porch
; .94uS approx 9 cycles
; resert VertCount3
movlw 0x21
movwf VertCount3
nop
nop
nop
nop
nop
nop
nop
; hysnc pulse
; 3.77uS approx 38 cycles
bcf PORTB, 7
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
nop
nop
nop
nop
bsf PORTB, 7
; hsync back porch
; 1.89uS approx 19 cycles
Delay10TCY
nop
nop
nop
nop
nop
nop
decfsz LineCount1
goto LineCounter1Loop
nop
LineCounter2Loop:
; 25.17uS display line approx 251 cycles
Delay100TCY
Delay100TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
; hsync front porch
; .94uS approx 9 cycles
nop
nop
nop
nop
nop
nop
nop
nop
nop
; hysnc pulse
; 3.77uS approx 38 cycles
bcf PORTB, 7
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
nop
nop
nop
nop
bsf PORTB, 7
; hsync back porch
; 1.89uS approx 19 cycles
Delay10TCY
nop
nop
nop
nop
nop
nop
decfsz LineCount2
goto LineCounter2Loop
nop
; blanking time before vert sync
VertCounter1Loop:
; 25.17uS display line approx 251 cycles
Delay100TCY
Delay100TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
; hsync front porch
; .94uS approx 9 cycles
nop
nop
nop
nop
nop
nop
nop
nop
nop
; hysnc pulse
; 3.77uS approx 38 cycles
bcf PORTB, 7
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
nop
nop
nop
nop
bsf PORTB, 7
; hsync back porch
; 1.89uS approx 19 cycles
Delay10TCY
nop
nop
nop
nop
nop
nop
decfsz VertCount1
goto VertCounter1Loop
bcf PORTB, 6 ; vert sync signal goes low
; 2 lines of vert sync
VertSyncLoop:
; 25.17uS display line approx 251 cycles
Delay100TCY
Delay100TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
; hsync front porch
; .94uS approx 9 cycles
nop
nop
nop
nop
nop
nop
nop
nop
nop
; hysnc pulse
; 3.77uS approx 38 cycles
bcf PORTB, 7
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
nop
nop
nop
nop
bsf PORTB, 7
; hsync back porch
; 1.89uS approx 19 cycles
Delay10TCY
nop
nop
nop
nop
nop
nop
decfsz VertCount2
goto VertSyncLoop
bsf PORTB, 6 ; vert sync goes high
; lines after vert sync
VertCounter3Loop:
; 25.17uS display line approx 251 cycles
Delay100TCY
Delay100TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
; hsync front porch
; .94uS approx 9 cycles
; reset the other line counters
setf LineCount1
movlw 0xE0
movwf LineCount2
movlw 0x0D
movwf VertCount1
movlw 0x02
movwf VertCount3
nop
nop
; hysnc pulse
; 3.77uS approx 38 cycles
bcf PORTB, 7
Delay10TCY
Delay10TCY
Delay10TCY
nop
nop
nop
nop
nop
nop
bsf PORTB, 7
; hsync back porch
; 1.89uS approx 19 cycles
Delay10TCY
nop
nop
nop
nop
nop
nop
decfsz VertCount3
goto VertCounter3Loop
goto VideoLoop
end