I'm drunk but I still got 4-bit GRAY SCALE BABY!
cbmeeks
Posts: 634
hahaha..
yeah, I've been drinking. Man, I have to be the best drunkin EE amateur on the planet...LMAO.
For those that don't know...I've spent a lot of time in the XGamestation forums building different types of circuits for my homebrew computer. Anyway, I built a video circuit a while back using a PIC16F88 so now, I have converted it to an SX28 running 50MIPS. Anyway, I am displaying 16 shades of gray (including black,white and sync) on an NTSC monitor.
I built a 4-bit DAC using resistors (R2R network) and I now have 16 shades of gray! Well, actually, I have 13 shades of gray because Sync s 0, black is 1, and white is 15.
Anyway, it's beautiful...if I can get my freakin' camera to work, I will take some pics. :-D
Here is the source code....and yes, I stole Andre's DELAY macro but it's so damn good, why try and re-invent it?
Hope this helps someone.
WOOOHOOO!!!!
cbmeeks
yeah, I've been drinking. Man, I have to be the best drunkin EE amateur on the planet...LMAO.
For those that don't know...I've spent a lot of time in the XGamestation forums building different types of circuits for my homebrew computer. Anyway, I built a video circuit a while back using a PIC16F88 so now, I have converted it to an SX28 running 50MIPS. Anyway, I am displaying 16 shades of gray (including black,white and sync) on an NTSC monitor.
I built a 4-bit DAC using resistors (R2R network) and I now have 16 shades of gray! Well, actually, I have 13 shades of gray because Sync s 0, black is 1, and white is 15.
Anyway, it's beautiful...if I can get my freakin' camera to work, I will take some pics. :-D
Here is the source code....and yes, I stole Andre's DELAY macro but it's so damn good, why try and re-invent it?
;=======================================================================
;TITLE: ntsc01
;
;PURPOSE: Create purty pictures in assembly language
;
;AUTHOR: cbmeeks
;
;CONNECTIONS:
; RB.0 - RB.3 to R2R ladder
;
;DETAILS:
;=======================================================================
;-------------------------- DEVICE DIRECTIVES --------------------------
DEVICE SX28,OSCHS2,TURBO
FREQ 50_000_000
IFDEF __SASM ;SASM Directives
DEVICE STACKX,OPTIONX
IRC_CAL IRC_SLOW
ELSE ;Parallax Assember Directives
DEVICE STACKX_OPTIONX
ENDIF
RESET Initialize
;------------------------------ VARIABLES ------------------------------
SYNC equ %00000000
BLACK equ %00000001
WHITE equ %00001111
GRAY2 equ 2
GRAY3 equ 3
GRAY4 equ 4
GRAY5 equ 5
GRAY6 equ 6
GRAY7 equ 7
GRAY8 equ 8
GRAY9 equ 9
GRAY10 equ 10
GRAY11 equ 11
GRAY12 equ 12
GRAY13 equ 13
GRAY14 equ 14
CLK_SCALE equ 5 ; used to make calling the DELAY macro easier
; set this to the frequency / 10,000,000
counter DS 1 ; general counter
counter2 DS 1 ; general counter
; **** MACROS *****************************************************************
; /////////////////////////////////////////////////////////////////////////////
DELAY MACRO clocks
; Thanks to Andre' Lamoth for this delay routine
; this macro can handle large delays up to 25,500 cycles, so to call it use the following
; constructions
; cycle delay
; DELAY(number_of_clocks)
; for 80 mhz clock, microsecond parameters
; DELAY(80*microseconds)
; example you want a 4.5 uS delay
; 80*4.5 = 360
; DELAY(360)
; the preprocessor can NOT do floating point math, so another construction would be to scale
; all values by 10 then multiply by 8 rather than 80, for example, a 4.5 uS delay could be
; written
; DELAY(8*45)
; which is a little more intuitive
; first compute fractional remainder of 10 and delay
IF (((clocks) // 10) > 0)
; first 3 clock chunks
REPT (((clocks) // 10)/3)
JMP $ + 1
ENDR
; now the remainder if any
REPT (((clocks) // 10)//3)
NOP
ENDR
ENDIF
; next multiples of 100
IF (((clocks) / 100) >= 1)
; delay 100*(clocks/100), loop equals 100, therefore 1*(clocks/100) iterations
mov counter, #((clocks)/100) ; (2)
:Loop
mov counter2, #24 ; (2)
:Loop100
djnz counter2, :Loop100 ; (4/2)
djnz counter, :Loop ; (4/2)
ENDIF
; last compute whole multiples of 10, and delay
IF (( ((clocks) // 100) / 10) >= 1)
; delay 10*(clocks/10), loop equals 10, therefore (clocks/10) iterations
mov counter, #( ((clocks) // 100) / 10) ; (2)
:Loop2
jmp $ + 1 ; (3)
jmp $ + 1 ; (3)
djnz counter, :Loop2 ; (4/2)
ENDIF
ENDM
;------------------------ INITIALIZATION ROUTINE -----------------------
Initialize
;Configure port settings
mov rb, #%00000000 ;Port A output zero
mov !rb,#%00000000 ;Port A all output
;---------------------------- MAIN PROGRAM -----------------------------
Main
; front porch 1.5us
mov rb, #BLACK ;2 cycles - black
DELAY (CLK_SCALE*15-2)
; hsync 4.7us
mov rb, #SYNC ;2 cycles - sync
DELAY (CLK_SCALE*47 - 2)
;delay for old TV's 3.8us
mov rb, #BLACK ; 2 cycles - black
DELAY (CLK_SCALE*38 - 2)
;begin scanline 10us
mov rb, #WHITE
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY14
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY13
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY12
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY11
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY10
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY9
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY8
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY7
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY6
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY5
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY4
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY3
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #GRAY2
DELAY (CLK_SCALE*30 - 2) ;3us
mov rb, #BLACK
DELAY (CLK_SCALE*115 - 2) ;11.5us
jmp Main ;goto main
Hope this helps someone.

WOOOHOOO!!!!
cbmeeks
