Code:
'*****************************************************************************
'*****************************************************************************
'
'PIC 18F2520 @ 4Mhz + Horloge EXT 32 768 Hz sur TMR1 ( interruptions @ 1Hz )
'Compte-Tours avec Capture sur TMR3 avec Horloge système / 8.
'
'Afficheur LCD 2*8 sur PORTD
'
' 3745 Lignes assembleur
'
'*****************************************************************************
'*****************************************************************************
'
'Defines
'*****************************************************************************
DEFINE OSC 4
DEFINE BUTTON_PAUSE 250
DEFINE ADC_BITS 10
'DEFINE LCD_COMMANDUS 2000
'DEFINE LCD_DATAUS 50
' Define LCD connections
DEFINE LCD_DREG PORTC ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 5 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 6 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
'
'
'*****************************************************************************
' Constantes
'*****************************************************************************
ExtOSC con 32768 'Quartz Horloge "temps" en Hz
Tension_ con 0 'Correspondance pour Canaux ADC
TempA_ con 1
TempH_ con 2
Dureetonte con 1 ' de -1h à +59 mn ... ( 1/2 durée !!! )
Kelvin con 273
'*************************** seuils Alarmes ********************************
AlmVolt con 15 * 100 '>= Tension trop élevée 1/100 V
AlmRpm con 3600 '>= Régime trop élevé T/Mn
AlmAir con 90 + 273 '>= Temp Air Trop élevée °K ^ 82
AlmHuileL con 0 + 273 '<= Temp Huile trop basse °K
AlmHuileH con 100 + 273 '>= Temp Huile trop élevée °K
'************** Periodicités d'Entretien ( ordre croissant ! ) *************
Service1 con 10 ' Heures
ServiceV con 20
Service2 con 25
Service3 con 50
Service4 con 100
Service5 con 300
VERSION con 1 'N° de la révision
DATA (0),0 (29) 'Raz des Mémoires si reprogrammation
'*****************************************************************************
' 1er préchargement 85H30M43S le 03/02/2010
'*****************************************************************************
DATA @0, VERSION
DATA @4, $1 ' Affichage maintenance ?
DATA @6, $55
DATA @8, $0 ' 85 Heures
DATA @10,$1E ' 30 Minutes
DATA @12,$2B ' 43 Secondes
DATA @14,$B8
DATA @16,$0B ' 3583 Tr/mn
DATA @22,$3C
DATA @24,$0 ' 83°C Air
DATA @26,$3C
DATA @28,$0 ' 89°C Huile
'*****************************************************************************
'*****************************************************************************
'Config processeur
'*****************************************************************************
'
@ __CONFIG _CONFIG1H, _IESO_OFF_1H & _OSC_XT_1H & _FCMEN_OFF_1H
@ __CONFIG _CONFIG2L, _BOREN_OFF_2L & _PWRT_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
@ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L & _XINST_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
'*****************************************************************************
'Config Osc
OSCCON = %01100000
'*****************************************************************************
'Config TIMERs
T0CON = %00000010 ' 16Bits 1/8 prescaler, Horloge Système, OFF
' Utilisé pour détection sous regime ou arret
T1CON = %00000000 '1/1 prescaler, Quartz 32,768
' *** Géré par Elapsed Timer ***
T3CON = %01110001 ' CCP SUR TMR3,1/8 prescaler,Horloge système,ON
' Mesure de la vitesse
'*****************************************************************************
'Config CCP1 arret CCP2
CCP1CON = %00000101 ' Capture sur front montant
CCP2CON = %00000000 'inhibition module CCP2
'*****************************************************************************
'Inhibition SSP
SSPCON1.5 = 0
'*****************************************************************************
'Inhibition Comparateurs
CMCON = 7
'*****************************************************************************
'Inhibition Reference interne
CVRCON = 0
'*****************************************************************************
'Config Interruptions
INTCON = %10000000
INTCON2 = %11110000
INTCON3 = %00000000
PIE1 = %00000100
PIE2 = %00000000
IPR1 = %00000001
IPR2 = %00000000
RCON = %10000000
'*****************************************************************************
'Config ADC
'*****************************************************************************
ADCON0 = %11000000 '
ADCON1 = %00011100 ' A0 > A2 Vref+ A3, Vref- = Vss
ADCON2 = %10100110 ' Right Just., 8Tad, clock /64
'*****************************************************************************
'*****************************************************************************
'Config et Prepositionnement E/S
'*****************************************************************************
PORTA = %00110000
PORTB = %00010000
PORTC = %00001000
TRISA = %00011111
TRISB = %00000110
TRISC = %00000111
'
'*****************************************************************************
'Alias E/S
'*****************************************************************************
'MCLR/ sur Broche 1 par R/C/D
Voltage var PORTA.0 'TENSION Batterie / 4
TempA var PORTA.1 'LM335 Temp Air
TempH var PORTA.2 'LM335 Temp Huile
Vref var PORTA.3 'TL431 = 4.096v ...
Raz var PORTA.4 'JUMPER Raz/Programmation
AlRef var PORTA.5 'Alimentation référence TL431 + capteurs
Buzzer var PORTB.0
Contact var PORTB.1 ' + 12 v sous clé ( / 4 = 2 - 4 v !!! )
Selection var PORTB.2 'Poussoir sélection Affichage
Signal var PORTB.3 'Sortie Survitesse
AlLCD var PORTB.4 'Alimentation LCD BS 250 !!! 0 = ON : 1 = OFF
RS var PORTB.5
E var PORTB.6
Alm var PORTB.7 'Sortie Alarme
' var PORTC.0 'Qz 32768
' var PORTC.1 ' "
Speed var PORTC.2 'Entrée compte-tours 1C/4T
Alim var PORTC.3 'Autoalimentation
D4 var PORTC.4
D5 var PORTC.5
D6 var PORTC.6
D7 var PORTC.7
'*****************************************************************************
'Types Variables
'*****************************************************************************
'
Result var WORD
Volt var WORD
Tension var WORD
Tensionmoy var WORD
Tair var WORD
TAMax var WORD ' Valeur Maxi Split
TairMax var WORD ' Valeur Maxi mémorisée
Thuile var WORD
THMax var WORD ' Valeur Maxi Split
THuileMax var WORD ' Valeur Maxi mémorisée
Dummy var WORD
Capture var WORD
CaptureOld var WORD
Vitesse var WORD
Vitessemoy var WORD
VitesseMax var WORD ' Valeur Maxi mémorisée
VitMaxSpl var WORD ' Valeur Maxi Split
Periode var WORD
Periode2 var WORD
MaxPeriode var WORD ' Pour calcul DIV32 ...
HoursT var WORD ' Memorisation Heures totales
HoursG var WORD
Service var WORD
LSelect var BYTE
SecondsT var BYTE ' Mémorisation Secondes Totales
MinutesT var BYTE ' Mémorisation Minutes Totales
AddH var BYTE ' Retenue 60M ...
AddM var BYTE ' Retenue 60s
Delay var BYTE
I var BYTE
RazT var BIT
Buzz var BIT
Reveil var BIT
Flagged var BIT
Display var BIT
INTCON.7 = 0 'Désactivation interruptions
Alim = 1 'Autoalimentation
AlLCD = 0 'Mise sous tension LCD
Alref = 1 'Mise sous tension référence
PAUSE 500
LCDOUT $FE,1 ' Initialize LCD
CLEAR
Periode2 = 3000
dummy = 2500*Periode2 'Juste Pour éviter de ralentir l'interruption ...
MaxPeriode = DIV32 AlmRpm
'*****************************************************************************
'Includes
'*****************************************************************************
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18_ExtOsc.bas" ; Elapsed Timer Routines
ASM
INT_LIST_H macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
INT_Handler CCP1_INT, _Period, PBP, yes
endm
INT_CREATE_H ; Creates the interrupt processor
ENDASM
...
Main: ' " active " code now
as you see ... it's not too far from assembler but banks selecting ( if any ...) and other " details " ( memory maps, "multibyte" variables types ...) are held by PBP ...
Bookmarks