Function fontread(addr As Word) As Byte
Dim lowbyte As Byte
Dim highbyte As Byte
lowbyte = addr.LB
highbyte = addr.HB
ASM: movlw low fnt
ASM: addwf lowbyte,w
ASM: movwf TBLPTRL,A
ASM: movlw high fnt
ASM: addwfc highbyte,w
ASM: movwf TBLPTRH,A
ASM: movlw upper fnt
ASM: addwfc upperbyte,w
ASM: movwf TBLPTRU,A
ASM: TBLRD*
ASM: movfw TABLAT,A
fontread = WREG
Goto fin
ASM:fnt: db 0x3e,0x51,0x49,0x45,0x3e
ASM: db 0x00,0x42,0x7f,0x40,0x00
ASM: db 0x42,0x61,0x51,0x49,0x46
ASM: db 0x21,0x41,0x45,0x4b,0x31
ASM: db 0x18,0x14,0x12,0x7F,0x10
ASM: db 0x27,0x45,0x45,0x45,0x39
ASM: db 0x3c,0x4a,0x49,0x49,0x30
ASM: db 0x01,0x71,0x09,0x05,0x03
ASM: db 0x36,0x49,0x49,0x49,0x36
ASM: db 0x06,0x49,0x49,0x29,0x1e
fin:
End Function
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Symbol ss = LATC.2
Symbol d_c = LATC.1
Symbol rst = LATC.0
TRISC = 0x10
Dim x As Word
Dim ret As Byte
Dim scrbuf(504) As Byte
Dim lp As Byte
OSCCON = 0x70
ADCON1 = 0xf
Call spi_init()
TRISA.5 = 0
LATA.5 = 0
lp = 22
WaitMs 10
Call initscreen()
loop:
Call clearscreen()
Call circle(42, 24, lp)
Call circle(42, 24, 4)
Call circle(42, 24, 22)
Call box(1, 1, 81, 47)
Call charput(4, 5, 65)
Call charput(10, 5, 66)
Call charput(16, 5, 67)
lp = lp - 1
If lp = 5 Then lp = 22
Call blit()
Goto loop
End
'----------------------------------------
Proc spi_init()
TRISC.5 = 0
TRISC.2 = 0
TRISC.4 = 1
TRISC.3 = 0
ss = 1
SSPSTAT = 0
'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
SSPCON1 = 0x20 'full whack... at 8mhz 2mhz operation no SS control
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc
'----------------------------------------
Function do_spi_8(data As Byte) As Byte
do_spi_8 = SSPBUF
SSPBUF = data
While Not SSPSTAT.BF
Wend
End Function
'----------------------------------------
Proc initscreen()
rst = 0
WaitMs 100
rst = 1
Call sendcommand(0x21)
Call sendcommand(0x13)
Call sendcommand(0x07)
Call sendcommand(0xc0)
Call sendcommand(0x20)
Call sendcommand(0x0c)
End Proc
'----------------------------------------
Proc blit()
d_c = 1
ss = 0
For x = 0 To 503
ret = do_spi_8(scrbuf(x))
Next x
ss = 1
End Proc
'----------------------------------------
Proc clearscreen()
For x = 0 To 503
scrbuf(x) = 0
Next x
End Proc
'----------------------------------------
Proc sendcommand(cmd As Byte)
d_c = 0
ss = 0
ret = do_spi_8(cmd)
ss = 1
End Proc
'----------------------------------------
Proc senddata(data As Byte)
d_c = 1
ss = 0
ret = do_spi_8(data)
ss = 1
End Proc
'----------------------------------------
Proc box(x1 As Word, y1 As Word, x2 As Word, y2 As Word)
Call line(x1, y1, x2, y1)
Call line(x1, y1, x1, y2)
Call line(x1, y2, x2, y2)
Call line(x2, y1, x2, y2)
End Proc
'----------------------------------------
Proc charput(x1 As Word, y1 As Word, ch As Byte)
Dim loop As Word
Dim addr As Word
Dim tmp As Word
Dim char As Byte
Dim tmp2 As Word
Dim shift As Byte
Dim shift2 As Byte
Dim msk As Byte
Dim msk2 As Byte
addr = ShiftRight(y1, 3)
shift = ShiftLeft(addr, 3)
shift = y1 - shift
shift2 = 8 - shift
addr = addr * 84
addr = addr + x1
ch = ch - 0x20
For loop = 0 To 4
tmp = ch * 5 + loop
char = fontread(tmp)
tmp2 = addr + loop
msk = scrbuf(tmp2)
msk2 = ShiftLeft(char, shift)
msk = msk Xor msk2
scrbuf(tmp2) = msk
tmp2 = addr + loop + 84
msk = scrbuf(tmp2)
msk2 = ShiftRight(char, shift2)
msk = msk Xor msk2
scrbuf(tmp2) = msk
Next loop
End Proc
'----------------------------------------
Proc circle(cx As Byte, cy As Byte, rad As Byte)
Dim x As Byte
Dim y As Byte
Dim tmpx As Word
Dim tmpy As Word
Dim xchange As Word
Dim ychange As Word
Dim radiuserror As Word
x = rad
y = 0
xchange = 1 - 2 * rad
ychange = 1
radiuserror = 1 - rad
While x >= y 'now the rest of them..
tmpx = cx + x
tmpy = cy + y
Call putpixel(tmpx, tmpy)
tmpx = cx - x
tmpy = cy + y
Call putpixel(tmpx, tmpy)
tmpx = cx - x
tmpy = cy - y
Call putpixel(tmpx, tmpy)
tmpx = cx + x
tmpy = cy - y
Call putpixel(tmpx, tmpy)
tmpx = cx + y
tmpy = cy + x
Call putpixel(tmpx, tmpy)
tmpx = cx - y
tmpy = cy + x
Call putpixel(tmpx, tmpy)
tmpx = cx - y
tmpy = cy - x
Call putpixel(tmpx, tmpy)
tmpx = cx + y
tmpy = cy - x
Call putpixel(tmpx, tmpy)
y = y + 1
radiuserror = radiuserror + ychange
ychange = ychange + 2
If radiuserror < 0x8000 And radiuserror >= 0 Then
x = x - 1
radiuserror = radiuserror + xchange
xchange = xchange + 2
Endif
Wend
End Proc
'----------------------------------------
Proc line(x1 As Word, y1 As Word, x2 As Word, y2 As Word)
Dim x As Word
Dim y As Word
Dim dx As Word
Dim dy As Word
Dim incx As Word
Dim incy As Word
Dim balance As Word
incx = 0
incy = 0
If x2 > x1 Then
dx = x2 - x1
incx = incx + 1
Else
dx = x1 - x2
incx = incx - 1
Endif
If y2 > y1 Then
dy = y2 - y1
incy = incy + 1
Else
dy = y1 - y2
incy = incy - 1
Endif
x = x1
y = y1
If dx >= dy Then
dy = ShiftLeft(dy, 1)
balance = dy - dx
dx = ShiftLeft(dx, 1)
While x <> x2
Call putpixel(x, y)
If balance < 0x8000 And balance >= 0 Then
y = y + incy
balance = balance - dx
Endif
balance = balance + dy
x = x + incx
Wend
Call putpixel(x, y)
Else
dx = ShiftLeft(dx, 1)
balance = dx - dy
dy = ShiftLeft(dy, 1)
While y <> y2
Call putpixel(x, y)
If balance < 0x8000 And balance >= 0 Then
x = x + incx
balance = balance - dy
Endif
balance = balance + dx
y = y + incy
Wend
Call putpixel(x, y)
Endif
End Proc
'----------------------------------------
Proc putpixel(x As Word, y As Word)
Dim addr As Word
Dim tmp As Word
Dim pix As Byte
Dim msk As Byte
tmp = ShiftRight(y, 3)
pix = ShiftLeft(tmp, 3)
pix = y - pix
tmp = tmp * 84
tmp = tmp + x
pix = LookUp(1, 2, 4, 8, 16, 32, 64, 128), pix
msk = scrbuf(tmp)
msk = msk Or pix
scrbuf(tmp) = msk
End Proc
'----------------------------------------
Function fontread(addr As Word) As Byte
Dim lowbyte As Byte
Dim highbyte As Byte
Dim upperbyte As Byte
lowbyte = addr.LB
highbyte = addr.HB
upperbyte = 0
ASM: movlw low fnt
ASM: addwf lowbyte,w
ASM: movwf TBLPTRL,A
ASM: movlw high fnt
ASM: addwfc highbyte,w
ASM: movwf TBLPTRH,A
ASM: movlw upper fnt
ASM: addwfc upperbyte,w
ASM: movwf TBLPTRU,A
ASM: TBLRD*
ASM: movfw TABLAT,A
fontread = WREG
Goto fin
ASM:fnt: db 0x00,0x00,0x00,0x00,0x00 ;(space)
ASM: db 0x00,0x00,0x5f,0x00,0x00 ;!
ASM: db 0x00,0x07,0x00,0x07,0x00 ;quotes
ASM: db 0x14,0x7f,0x14,0x7f,0x14 ;#
ASM: db 0x24,0x2a,0x7f,0x2a,0x12 ;$
ASM: db 0x23,0x13,0x08,0x64,0x62 ;%
ASM: db 0x36,0x49,0x55,0x22,0x50 ;&
ASM: db 0x00,0x05,0x03,0x00,0x00 ;/
ASM: db 0x00,0x1c,0x22,0x41,0x00 ;(
ASM: db 0x00,0x41,0x22,0x1c,0x00 ;)
ASM: db 0x08,0x2a,0x1c,0x2a,0x08 ;*
ASM: db 0x08,0x08,0x3e,0x08,0x08 ;+
ASM: db 0x00,0x50,0x30,0x00,0x00 ;,
ASM: db 0x08,0x08,0x08,0x08,0x08 ;-
ASM: db 0x00,0x30,0x30,0x00,0x00 ;.
ASM: db 0x20,0x10,0x08,0x04,0x02 ;/
ASM: db 0x3e,0x51,0x49,0x45,0x3e ;0
ASM: db 0x00,0x42,0x7f,0x40,0x00 ;1
ASM: db 0x42,0x61,0x51,0x49,0x46 ;2
ASM: db 0x21,0x41,0x45,0x4b,0x31 ;3
ASM: db 0x18,0x14,0x12,0x7F,0x10 ;4
ASM: db 0x27,0x45,0x45,0x45,0x39 ;5
ASM: db 0x3c,0x4a,0x49,0x49,0x30 ;6
ASM: db 0x01,0x71,0x09,0x05,0x03 ;7
ASM: db 0x36,0x49,0x49,0x49,0x36 ;8
ASM: db 0x06,0x49,0x49,0x29,0x1e ;9
ASM: db 0x00,0x36,0x36,0x00,0x00 ;:
ASM: db 0x00,0x56,0x36,0x00,0x00 ;;
ASM: db 0x00,0x08,0x14,0x22,0x41 ;<
ASM: db 0x14,0x14,0x14,0x14,0x14 ;=
ASM: db 0x41,0x22,0x14,0x08,0x00 ;>
ASM: db 0x02,0x01,0x51,0x09,0x06 ;?
ASM: db 0x32,0x49,0x79,0x41,0x3E ;@
ASM: db 0x7E,0x11,0x11,0x11,0x7E ;A
ASM: db 0x7F,0x49,0x49,0x49,0x36 ;B
ASM: db 0x3E,0x41,0x41,0x41,0x22 ;C
fin:
End Function
Yeah! now try running on a real device.... I can run it in ISIS and it doesn't get anywhere..extended it by copy/paste the asm chars, now have 350 lines of asm chars, it assembles OK.?
hi Ian,Swapped it all over to 3.3v (I used a 74hc125 ) bridged out the LDO.... Perfect!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?