'****************************************************************
'*  Name    : Dev_board_demo.BAS                                *
'*  Author  : Coenen Stijn [Stynus]                             *
'*  Notice  : Copyright (c) 2008 © Elektronica Stynus           *
'*          : All Rights Reserved                               *
'*  Date    : 23/12/2008                                        *
'*  Version : 1.2                                               *
'*  Voor meer info zie:                                         *
'*  http://www.schematheek.net/index.php?p=forum/topic&t=72     *
'****************************************************************
Device  16F877A
Config  WDT_Off, PWRTE_ON, HS_OSC , LVP_off
Xtal    20
All_Digital = true

'****************************************************************
'RS232
    'Symbol TX        = PORTC.6
    'Symbol RX        = PORTC.7
    Hserial_Clear    = On         'Zorgt ervoor dat de buffer automatisch 
                                  'leeg wordt gemaakt voordat er data wordt 
                                  'ontvangen
    Declare Hserial_Baud    9600  'Snelheid op 9600 bits/seconde instellen
    Hserial_RCSTA    = %10010000  'Hardware seriële poort opzetten in 
                                  'continue mode
    Hserial_TXSTA    = %00100000  'Verzenden via uart opzetten in assynchrone
                                  'mode
    INTCON = %11000000 			  'Interrupt opzetten
    On_Interrupt     GoTo SeriIn  'Bij interrupt naar SeriIn springen 
    PIE1.5 = 1                    'Interrupt voor usart opzetten
    
    Symbol  klok      = PORTB.5
    Symbol  ZetVast   = PORTB.4
   
    Symbol  Data0     = PORTD.1 : TRISD.1 = 0
    Symbol  Data1     = PORTD.0 : TRISD.0 = 0
    Symbol  Data2     = PORTC.3 : TRISC.3 = 0
    Symbol  Data3     = PORTC.2 : TRISC.2 = 0
    Symbol  Data4     = PORTC.1 : TRISC.1 = 0
    Symbol  Data5     = PORTC.0 : TRISC.0 = 0
    Symbol  Data6     = PORTE.2 : TRISE.2 = 0 
    Symbol  Data7     = PORTB.3 : TRISB.3 = 0
    
'****************************************************************   
'Variabelen declareren
    Dim     temp       As Byte
    Dim     index      As Byte
    Dim     serdata    As Byte
    
    Dim     display[53] As Byte 
    Dim     aanst_count As Byte
    
    Dim i As Byte
    Dim x As Byte
    Dim loop As Word
    Dim modulus As Byte
    Dim delen As Byte
    
    Dim einde As Word
'****************************************************************    
Clear   
'****************************************************************
EData  "SchemaTheek.net       Bedankt Reddevil!!         ", $FFFF

GoTo Main

Main:
    For loop = 0 To 50 * 5
        modulus = loop // 6
        For i = 0 To 8 
            For x = 4 To 0 Step -1
                index = (i*6) + x - modulus
                delen = loop /6
                display[index] = CRead  Font + ((ERead i + delen)*5) + x 
            Next
            index = (i*6)+5 - modulus
            display[index] = %00000000
        Next
        'display[31] = $FF
        GoSub Uitsturen
        DelayMS 200
    Next      
GoTo Main
'****************************************************************
Uitsturen:

    'Data uitgangen laag voor eerste klokpuls
    Low Data0 : Low Data1 : Low Data2 : Low Data3
    Low Data4 : Low Data5 : Low Data6 : Low Data7
    
    'KlokPuls:
    High klok : nop : Low klok : nop       
    
    'Schuifregisters vullen 
    For aanst_count = 48 To 0 Step -1
        'De laagste bits van temp data in de schuifregisters klokken
        temp = display[aanst_count]
        Data7 = temp.0 +1 
        Data6 = temp.1 +1 
        Data5 = temp.2 +1 
        Data4 = temp.3 +1 
        Data3 = temp.4 +1 
        Data2 = temp.5 +1 
        Data1 = temp.6 +1 
        Data0 = temp.7 +1 
        
       'KlokPuls:
        High klok : nop : Low klok : nop    
        
        'temp_Data byte's 1 plaats naar rechts opschuiven
        '   Bij de volgende loop komt de volgende bit dan in het 
        '   schuifregister terecht. 
    Next 
    'Data op de uitgang van de schuifregisters zetten
    High ZetVast : nop : Low ZetVast
Return


DataShift:

Return
SeriIn:                           'Interrupt routine
    HSerIn [serdata]              'ontvangen data in serdata zetten
    Print serdata                 'ontvangen data op het lcd printen
    HSerOut [serdata]             'Data terug naar pc sturen ter
                                  'bevestiging
Context Restore                   'Data herstellen en teruggaan
'****************************************************************   
End
Font:-	CData $00,$00,$00,$00,$00		'Graphic character 0
		CData $FF,$FF,$FF,$FF,$FF		'Graphic character 1
		CData $07,$07,$07,$00,$00		'Graphic character 2
        CData $00,$00,$00,$07,$07		'Graphic character 3
        CData $E0,$E0,$E0,$00,$00		'Graphic character 4
        CData $00,$00,$00,$E0,$E0		'Graphic character 5
        CData $FF,$FF,$FF,$00,$00		'Graphic character 6
        CData $00,$00,$00,$FF,$FF		'Graphic character 7
        CData $07,$07,$07,$07,$07		'Graphic character 8
        CData $E0,$E0,$E0,$E0,$E0		'Graphic character 9
        CData $E0,$E0,$E0,$07,$07		'Graphic character 10
        CData $07,$07,$07,$E0,$E0		'Graphic character 11
        CData $FF,$FF,$FF,$E0,$E0		'Graphic character 12
        CData $E0,$E0,$E0,$FF,$FF		'Graphic character 13
        CData $07,$07,$07,$FF,$FF		'Graphic character 14
        CData $FF,$FF,$FF,$07,$07		'Graphic character 15
        CData $55,$AA,$55,$AA,$55		'Graphic character 16
        CData $AA,$55,$AA,$55,$AA		'Graphic character 17
        CData $01,$01,$01,$01,$01		'Graphic character 18
        CData $80,$80,$80,$80,$80		'Graphic character 19
        CData $FF,$00,$00,$00,$00		'Graphic character 20
        CData $00,$00,$00,$00,$00		'Graphic character 21
        CData $FF,$01,$01,$01,$01		'Graphic character 22
        CData $01,$01,$01,$01,$01		'Graphic character 23
        CData $FF,$80,$80,$80,$80		'Graphic character 24
        CData $80,$80,$80,$80,$80		'Graphic character 25
        CData $00,$00,$00,$00,$F0   	'User defined character 26
        CData $00,$00,$00,$00,$0F		'User defined character 27
        CData $00,$00,$00,$00,$00		'User defined character 28
        CData $00,$00,$00,$00,$00		'User defined character 29
        CData $00,$00,$00,$00,$00		'User defined character 30
        CData $00,$00,$00,$00,$00		'User defined character 31
        CData $00,$00,$00,$00,$00		'32 -   - 20        
		CData 0, 0, 242, 0, 0		'33 - ! - 21
		CData $00,$07,$00,$07,$00		'34 - " - 22
		CData $14,$7F,$14,$7F,$14		'35 - # - 23
		CData $24,$2A,$7F,$2A,$12		'36 - $ - 24
		CData $23,$13,$08,$64,$62		'37 - % - 25
		CData $36,$49,$55,$22,$50		'38 - & - 26
		CData $00,$05,$03,$00,$00		'39 - ' - 27
		CData $1C,$22,$41,$00,$00		'40 - ( - 28
		CData $00,$00,$41,$22,$1C		'41 - ) - 29
		CData $14,$08,$3E,$08,$14		'42 - * - 2A
		CData $08,$08,$3E,$08,$08		'43 - + - 2B
		CData $00,$50,$30,$00,$00		'44 - , - 2C
		CData $08,$08,$08,$08,$08		'45 - - - 2D
		CData 0, 6, 6, 0, 0		'46 - . - 2E
		CData $20,$10,$08,$04,$02	'47 - / - 2F
		CData $3E,$51,$49,$45,$3E		'48 - 0 - 30
		CData $00,$42,$7F,$40,$00		'49 - 1 - 31
		CData $42,$61,$51,$49,$46		'50 - 2 - 32
		CData $21,$41,$45,$4B,$31		'51 - 3 - 33
		CData $18,$14,$12,$7F,$10		'52 - 4 - 34
		CData $27,$45,$45,$45,$39		'53 - 5 - 35
		CData $3C,$4A,$49,$49,$30		'54 - 6 - 36
		CData $01,$71,$09,$05,$03		'55 - 7 - 37
		CData $36,$49,$49,$49,$36		'56 - 8 - 38
		CData $06,$49,$49,$49,$3E		'57 - 9 - 39
		CData $00,$36,$36,$00,$00		'58 - : - 3A
		CData $00,$56,$36,$00,$00		'59 - ; - 3B
		CData $08,$14,$22,$41,$00		'60 - < - 3C
		CData $14,$14,$14,$14,$14		'61 - = - 3D
		CData $00,$41,$22,$14,$08		'62 - > - 3E
		CData $02,$01,$51,$09,$06		'63 - ? - 3F
		CData $32,$49,$79,$41,$3E		'64 - @ - 40
		CData 62, 72, 136, 72, 62		'65 - A - 41
		CData 130, 254, 146, 146, 108		    '66 - B - 42
		CData 124, 130, 130, 130, 68		'67 - C - 43
		CData 124, 130, 130, 130, 68		'68 - D - 44
		CData $7F,$49,$49,$49,$41		'69 - E - 45
		CData $7F,$09,$09,$09,$01		'70 - F - 46
		CData $3E,$41,$49,$49,$7A		'71 - G - 47
		CData $7F,$08,$08,$08,$7F		'72 - H - 48
		CData $00,$41,$7F,$41,$00		'73 - I - 49
		CData $20,$40,$41,$3F,$01		'74 - J - 4A
		CData $7F,$08,$14,$22,$41		'75 - K - 4B
		CData $7F,$40,$40,$40,$40		'76 - L - 4C
		CData $7F,$02,$0C,$02,$7F		'77 - M - 4D
		CData $7F,$04,$08,$10,$7F		'78 - N - 4E
		CData $3E,$41,$41,$41,$3E		'79 - O - 4F
		CData $7F,$09,$09,$09,$06		'80 - P - 50
		CData $3E,$41,$51,$21,$5E		'81 - Q - 51
		CData 254, 144, 152, 148, 98		'82 - R - 52
		CData 100, 146, 146, 146, 76		'83 - S - 53
		CData 128, 128, 254, 128, 128		'84 - T - 54
		CData $3F,$40,$40,$40,$3F		'85 - U - 55
		CData $1F,$20,$40,$20,$1F		'86 - V - 56
		CData $3F,$40,$38,$40,$3F		'87 - W - 57
		CData $63,$14,$08,$14,$63		'88 - X - 58
		CData $07,$08,$70,$08,$07		'89 - Y - 59
		CData $61,$51,$49,$45,$43		'90 - Z - 5A
		CData $7F,$41,$41,$00,$00		'91 - [ - 5B
		CData $02,$04,$08,$10,$20		'92 - \ - 5C
		CData $00,$00,$41,$41,$7F		'93 - ] - 5D
		CData $04,$02,$01,$02,$04		'94 - ^ - 5E
		CData $40,$40,$40,$40,$40		'95 - _ - 5F
		CData $00,$01,$02,$04,$00		'96 - ` - 60
		CData 4, 42, 42, 42, 30		'97 - a - 61
		CData $7F,$48,$44,$44,$38		'98 - b - 62
		CData 28, 34, 34, 34, 34	      '99 - c - 63
		CData 12, 18, 18, 18, 254		'100  d - 64
		CData 28, 42, 42, 42, 26		'101  e - 65
		CData $08,$7E,$09,$01,$02		'102  f - 66
		CData $0C,$52,$52,$52,$3E		'103  g - 67
		CData 254, 16, 32, 32, 30		'104  h - 68
		CData 0, 0, 94, 0, 0		'105  i - 69
		CData $00,$20,$40,$44,$3D		'106  j - 6A
		CData 0, 254, 8, 20, 34		'107  k - 6B
		CData 0, 130, 254, 2, 0		'108  l - 6C
		CData 62, 32, 28, 32, 62		'109  m - 6D
		CData 62, 16, 32, 32, 30		'110  n - 6E
		CData $38,$44,$44,$44,$38		'111  o - 6F
		CData $7C,$14,$14,$14,$08		'112  p - 70
		CData $08,$14,$14,$18,$7C		'113  q - 71
		CData $7C,$08,$04,$04,$08		'114  r - 72
		CData $48,$54,$54,$54,$20		'115  s - 73
		CData 32, 32, 252, 34, 36		'116  t - 74
		CData $3C,$40,$40,$20,$7C		'117  u - 75
		CData 56, 4, 2, 4, 56		'118  v - 76
		CData $3C,$40,$30,$40,$3C		'119  w - 77
		CData $44,$28,$10,$28,$44		'120  x - 78
		CData $0C,$50,$50,$50,$3C		'121  y - 79
		CData $44,$64,$54,$4C,$44		'122  z - 7A
		CData $08,$36,$41,$00,$00		'123  { - 7B
		CData $00,$00,$7F,$00,$00		'124  | - 7C
		CData $00,$00,$41,$36,$08		'125  } - 7D
		CData $00,$08,$04,$08,$04 		'126  ~ - 7E