Vga pic 12f675

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I've been stuck on trying to debug this code. I have used the MPLAB debugger and it seems to work perfectly but when I put it on the chip its not doing what I want. The code as is on my PIC is configured to have oscillation pulses to display pixels through a vga port. My GPIO 0, 1 and 2 act as a 3 bit binary counter to display colors and resets when GPIO 3 is high. So I basically display black through white each HSYNC pulse. My GPIO 4 bit outputs a HSYNC frequency at 29.57Hz which is a little low but I can eventually change it to be faster. My problem lies on the GPIO 5 bit which acts as my VSYNC. My code is configured to display a color band per VSYNC drawing at 60 frames a second. So the first second of drawing displays black, red and so on in sequence. While the next second would start with red instead of black but would cycle through all the colors.

For some weird reason my GPIO 5 bit is somehow being brought low within the main chunk of the code. The only time I set the VSYNC low is when I use the delay loop so that should give me around 60Hz. Instead I am reading 25.91KHz on my multimeter when I probe GPIO 5.

I'm using header file P12F675.inc and linker script 12F675_g.lkr fyi. Don't know if that could affect why it isn't working.

Any suggestions as to what is happening?

Rich (BB code):
list      p=12f675            ; list directive to define processor
#include <p12f675.inc>        ; processor specific variable definitions

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 
 
;*************************** REGISTERS ********************************

cblock	0x20
	DelayCounter					; register location DelayCounter will contain number of loops that GPIO 5 is low
	GPCounter						; register location GPCounter will contain status of color to be drawn per second
	VSYNC							; register location VSYNC will contain number of loops before GPIO is set low
	PixelCounter					; register location PixelCounter will contain number of loops per line draw
	NA								; unused file location
	ThreeCount						; register location ThreeCount will contain number of loops outside loops for VSYNC
endc

;*************************** CONSTANTS ********************************	

#define Bank0		banksel 0x00		; first registerr bank = Bank 0
#define Bank1		banksel 0x80		;second register bank = Bank 1
#define ConfigTRI	B'00001000'			; Configure I/O

;******************** INITIALIZATION PROTOCOL **************************

	org     0x000				; BIG BANG
	goto	Initialize			; Initialization call
	org		0x005				; Start of Programm Memory Vector

Initialize

	Bank0						; Bank 0 located at 0x00h
	movlw	03h					; store 03 in 
	movwf	ThreeCount			; ThreeCount 
	movlw	0A0h				; store A0 in
	movwf	VSYNC				; VSYNC which means VSYNC is set low when A0 * 3 loops have been iterated
	movlw 	07h					; store 07 in  
	movwf	PixelCounter		; PixelCounter so 7 colors can be drawn per line
	movwf 	CMCON 				; CMCON so digital configuration is set
	movlw	30h					; move binary value 00110000 
	movwf	GPIO				; Hsync and Vsync are set by having GPIO 5,4 high

	Bank1						; Bank 1 located at 0x20h
	clrw 						; clear w register		
	clrf 	ANSEL 				; clear ANSEL register which controls analog or digital configuration making DIGITAL	
	movlw 	ConfigTRI 			; loads constant ConfigTRI
	movwf 	TRISIO 				; loads w register into TRISIO register which assigns I/O for GPIO pins

	Bank0						; return to Bank0 address

Main
	incf	GPIO,1				; increments gpio every pixel draw showing all 7 colors
	decfsz	PixelCounter,1		; when 7 colors are drawn then restart line
	goto	Main
	movlw	20h					; move binary value 00100000 clears HSYNC 
	movwf	GPIO				; clears GPIO 4 
	movlw	07h					; move 7 to register w
	movwf	PixelCounter		; PixelCounter gets reset to 7 
	movlw	10h					; move 10h to w
	addwf	GPCounter,0			; add that value to color status
	addwf	GPIO,1				; move the contents of w and GPIO into GPIO setting first color draw
	decfsz	VSYNC,1				; decrement VSYNC
	goto	Main
	movlw	0A0h				; resets VSYNC with 
	movwf	VSYNC				; A0h
	decfsz	ThreeCount,1		; decrements ThreeCount		
	goto	Main
	movlw	03h					; move 3 to register w
	movwf	ThreeCount			; reset ThreeCount
	clrf	GPIO				; clear GPIO for Hsync and Vsync low pulse
	movlw	49h					; move 49h to
	movwf	DelayCounter		; DelayCounter which sets Vsync's low time	

;Vsync and Hsync low pulse

DelayLoop						; This loop will eventually be used to configure pixels	
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	DelayCounter		; decrement until DelayCounter is 0 
	goto	DelayLoop			; then skip loop
	incf	GPCounter,1			; increment GPCounter which keeps track of color to be drawn first
	btfsc	GPCounter,3			; check GPIO bit 3 and if set reset color sequence to original
	call	RGPCounter			; reset GPCounter
	movlw	30h					; set Hsync and Vsync to start drawing again
	addwf	GPIO,1				; add it to GPIO
	movf	GPCounter,0			; move contents in GPCounter to w
	addwf	GPIO,1				; add w and GPIO and then place in GPIO register
	goto	Main				; return to main loop

RGPCounter
	movlw	00h							; move binary value 00110111
	movwf	GPCounter					; Hsync and Vsync is set being the 5th and 6th bit on GPIO	
	return
end
 
Top