Artikel: [code] 16F877A development board demo code

Dit is de om alle functies van het 16F877A development bordje uit te testen.

De code met opmaak is hier te vinden:
https://www.schematheek.net/code/16F877A_devboard/demo.htm

'****************************************************************
'* 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: *
'* https://www.schematheek.net/index.php?p=forum/topic&t=72 *
'****************************************************************
Device 16F877A
Config WDT_Off, PWRTE_ON, HS_OSC , PWRTE_ON, LVP_off
XTAL 20
ALL_DIGITAL = true
'****************************************************************
'Pinnen declareren.
'Leds
Symbol Led1 = PORTD.1 : TRISD.1 = 0
Symbol Led2 = PORTD.0 : TRISD.0 = 0
Symbol Led3 = PORTC.3 : TRISC.3 = 0
Symbol Led4 = PORTC.2 : TRISC.2 = 0
Symbol Led5 = PORTC.1 : TRISC.1 = 0
Symbol Led6 = PORTC.0 : TRISC.0 = 0
Symbol Led7 = PORTE.2 : TRISE.2 = 0
'Schakelaars
Symbol Switch1 = PORTA.0 : TRISA.0 = 1
Symbol Switch2 = PORTA.1 : TRISA.1 = 1
Symbol Switch3 = PORTA.2 : TRISA.2 = 1
Symbol Switch4 = PORTA.3 : TRISA.3 = 1
Symbol Switch5 = PORTA.4 : TRISA.4 = 1
Symbol Switch6 = PORTA.5 : TRISA.5 = 1
Symbol Switch7 = PORTE.0 : TRISE.0 = 1
Symbol Switch8 = PORTE.1 : TRISE.1 = 1
'7 segment displays
Symbol DigitSel = PORTB.0 : TRISB.0 = 0
Symbol Digita = PORTB.7 : TRISB.7 = 0
Symbol Digitb = PORTB.6 : TRISB.6 = 0
Symbol Digitc = PORTB.5 : TRISB.5 = 0
Symbol Digitd = PORTB.4 : TRISB.4 = 0
Symbol Digite = PORTB.3 : TRISB.3 = 0
Symbol Digitf = PORTB.2 : TRISB.2 = 0
Symbol Digitg = PORTB.1 : TRISB.1 = 0
'Lcd
Declare LCD_DTPIN PORTD.4
Declare LCD_ENPIN PORTD.2
Declare LCD_RSPIN PORTD.3
Declare LCD_INTERFACE 4
Declare LCD_LINES 2
'RS232
'Symbol TX = PORTC.6
'Symbol RX = PORTC.7
HSERIAL_CLEAR = On
Declare HSERIAL_BAUD 9600
HSERIAL_RCSTA = %10010000
HSERIAL_TXSTA = %00100000
INTCON = %11000000
ON_INTERRUPT GoTo SeriIn
PIE1.5 = 1
'I?C bus
'(Op deze aansluitingen is op het dev boardje niks aangesloten)
Symbol SDO = PORTC.5
Symbol SDI = PORTC.4
'****************************************************************
'Variabelen declareren
Dim KnightTel As Byte
Dim knightbit As Bit
Dim digit1 As Byte
Dim digit2 As Byte
Dim digitval As Byte
Dim digitbit As Bit
Dim vertraging As Byte
Dim serdata As Byte
'****************************************************************
Clear
GoSub SerUit
Cls
Print At 1,1, "SchemaTheek.Net"
Print At 2,1, "16F877 ontwikkelbord"
Print $FE, 2
'****************************************************************
Main:
If vertraging = 100 Then
GoSub Knightrider
vertraging = 0
Else
Inc vertraging
EndIf
GoSub SwitchIn
GoSub Dispuit
GoTo Main
'****************************************************************
SerUit:
HSerOut ["***********************************", 13,10]
HSerOut ["* SchemaTheek.Net *", 13,10]
HSerOut ["* PIC16F877A ontwikkelbordje *", 13,10]
HSerOut ["* Demo programma V1.2 *", 13,10]
HSerOut ["* Laatste update: 23/12/2008 *", 13,10]
HSerOut ["***********************************", 13,10]
HSerOut ["Type hier uw tekst voor op het lcd:", 13,10]
Return
'****************************************************************
SeriIn:
HSerIn [serdata]
Print serdata
HSerOut [serdata]
Context Restore
'****************************************************************
SwitchIn:
digit1.3 = Switch4 +1
digit1.2 = Switch3 +1
digit1.1 = Switch2 +1
digit1.0 = Switch1 +1
digit2.3 = Switch8 +1
digit2.2 = Switch7 +1
digit2.1 = Switch6 +1
digit2.0 = Switch5 +1
Return
'****************************************************************
Dispuit:
If digitbit = 0 Then
Low DigitSel
digitval = digit1
digitbit = 1
Else
High DigitSel
digitval = digit2
digitbit = 0
EndIf
DelayMS 1
Select digitval
Case 0
High Digita
High Digitb
High Digitc
High Digitd
High Digite
High Digitf
Low Digitg
Case 1
Low Digita
High Digitb
High Digitc
Low Digitd
Low Digite
Low Digitf
Low Digitg
Case 2
High Digita
High Digitb
Low Digitc
High Digitd
High Digite
Low Digitf
High Digitg
Case 3
High Digita
High Digitb
High Digitc
High Digitd
Low Digite
Low Digitf
High Digitg
Case 4
Low Digita
High Digitb
High Digitc
Low Digitd
Low Digite
High Digitf
High Digitg
Case 5
High Digita
Low Digitb
High Digitc
High Digitd
Low Digite
High Digitf
High Digitg
Case 6
High Digita
Low Digitb
High Digitc
High Digitd
High Digite
High Digitf
High Digitg
Case 7
High Digita
High Digitb
High Digitc
Low Digitd
Low Digite
Low Digitf
Low Digitg
Case 8
High Digita
High Digitb
High Digitc
High Digitd
High Digite
High Digitf
High Digitg
Case 9
High Digita
High Digitb
High Digitc
High Digitd
Low Digite
High Digitf
High Digitg
Case 10 'A
High Digita
High Digitb
High Digitc
Low Digitd
High Digite
High Digitf
High Digitg
Case 11 'B
Low Digita
Low Digitb
High Digitc
High Digitd
High Digite
High Digitf
High Digitg
Case 12 'C
High Digita
Low Digitb
Low Digitc
High Digitd
High Digite
High Digitf
Low Digitg
Case 13 'D
Low Digita
High Digitb
High Digitc
High Digitd
High Digite
Low Digitf
High Digitg
Case 14 'E
High Digita
Low Digitb
Low Digitc
High Digitd
High Digite
High Digitf
High Digitg
Case 15 'F
High Digita
Low Digitb
Low Digitc
Low Digitd
High Digite
High Digitf
High Digitg
Case Else
Low Digita
Low Digitb
Low Digitc
Low Digitd
Low Digite
Low Digitf
High Digitg
EndSelect
DelayMS 1
Low Digita
Low Digitb
Low Digitc
Low Digitd
Low Digite
Low Digitf
Low Digitg
Return
'****************************************************************
Knightrider:
If knightbit = 0 Then
Inc KnightTel
If KnightTel = 7 Then
knightbit = 1
EndIf
Else
Dec KnightTel
If KnightTel = 1 Then
knightbit = 0
EndIf
EndIf
Select KnightTel
Case 1
High Led1
Low Led2
Low Led3
Low Led4
Low Led5
Low Led6
Low Led7
Case 2
Low Led1
High Led2
Low Led3
Low Led4
Low Led5
Low Led6
Low Led7
Case 3
Low Led1
Low Led2
High Led3
Low Led4
Low Led5
Low Led6
Low Led7
Case 4
Low Led1
Low Led2
Low Led3
High Led4
Low Led5
Low Led6
Low Led7
Case 5
Low Led1
Low Led2
Low Led3
Low Led4
High Led5
Low Led6
Low Led7
Case 6
Low Led1
Low Led2
Low Led3
Low Led4
Low Led5
High Led6
Low Led7
Case 7
Low Led1
Low Led2
Low Led3
Low Led4
Low Led5
Low Led6
High Led7
Case Else
High Led1
High Led2
High Led3
High Led4
High Led5
High Led6
High Led7
EndSelect
Return
'****************************************************************
End

Een reactie achterlaten

Your email address will not be published.