Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "p18f25k40.inc"
- ; CONFIG1L
- CONFIG FEXTOSC = ECH ; External Oscillator mode Selection bits (EC (external clock) above 8 MHz; PFM set to high power)
- CONFIG RSTOSC = HFINTOSC_64MHZ; Power-up default value for COSC bits (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1)
- ; CONFIG1H
- CONFIG CLKOUTEN = ON ; Clock Out Enable bit (CLKOUT function is disabled)
- CONFIG CSWEN = ON ; Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
- CONFIG FCMEN = ON ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
- ; CONFIG2L
- CONFIG MCLRE = EXTMCLR ; Master Clear Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR )
- CONFIG PWRTE = OFF ; Power-up Timer Enable bit (Power up timer disabled)
- CONFIG LPBOREN = OFF ; Low-power BOR enable bit (ULPBOR disabled)
- CONFIG BOREN = SBORDIS ; Brown-out Reset Enable bits (Brown-out Reset enabled , SBOREN bit is ignored)
- ; CONFIG2H
- CONFIG BORV = VBOR_2P45 ; Brown Out Reset Voltage selection bits (Brown-out Reset Voltage (VBOR) set to 2.45V)
- CONFIG ZCD = OFF ; ZCD Disable bit (ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
- CONFIG PPS1WAY = ON ; PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
- CONFIG STVREN = ON ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
- CONFIG DEBUG = OFF ; Debugger Enable bit (Background debugger disabled)
- CONFIG XINST = OFF ; Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)
- ; CONFIG3L
- CONFIG WDTCPS = WDTCPS_31 ; WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS)
- CONFIG WDTE = OFF ; WDT operating mode (WDT enabled regardless of sleep)
- ; CONFIG3H
- CONFIG WDTCWS = WDTCWS_7 ; WDT Window Select bits (window always open (100%); software control; keyed access not required)
- CONFIG WDTCCS = SC ; WDT input clock selector (Software Control)
- ; CONFIG4L
- CONFIG WRT0 = OFF ; Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
- CONFIG WRT1 = OFF ; Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
- CONFIG WRT2 = OFF ; Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
- CONFIG WRT3 = OFF ; Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)
- ; CONFIG4H
- CONFIG WRTC = OFF ; Configuration Register Write Protection bit (Configuration registers (300000-30000Bh) not write-protected)
- CONFIG WRTB = OFF ; Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
- CONFIG WRTD = OFF ; Data EEPROM Write Protection bit (Data EEPROM not write-protected)
- CONFIG SCANE = ON ; Scanner Enable bit (Scanner module is available for use, SCANMD bit can control the module)
- CONFIG LVP = ON ; Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)
- ; CONFIG5L
- CONFIG CP = OFF ; UserNVM Program Memory Code Protection bit (UserNVM code protection disabled)
- CONFIG CPD = OFF ; DataNVM Memory Code Protection bit (DataNVM code protection disabled)
- ; CONFIG5H
- ; CONFIG6L
- CONFIG EBTR0 = OFF ; Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR1 = OFF ; Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR2 = OFF ; Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
- CONFIG EBTR3 = OFF ; Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
- ; CONFIG6H
- CONFIG EBTRB = OFF ; Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
- ;*******************************************************************************
- ;
- ; TODO Step #3 - Variable Definitions
- ;
- ; Refer to datasheet for available data memory (RAM) organization assuming
- ; relocatible code organization (which is an option in project
- ; properties > mpasm (Global Options)). Absolute mode generally should
- ; be used sparingly.
- ;
- ; Example of using GPR Uninitialized Data
- ;
- ; GPR_VAR UDATA
- ; MYVAR1 RES 1 ; User variable linker places
- ; MYVAR2 RES 1 ; User variable linker places
- ; MYVAR3 RES 1 ; User variable linker places
- ;
- ; ; Example of using Access Uninitialized Data Section (when available)
- ; ; The variables for the context saving in the device datasheet may need
- ; ; memory reserved here.
- ; INT_VAR UDATA_ACS
- ; W_TEMP RES 1 ; w register for context saving (ACCESS)
- ; STATUS_TEMP RES 1 ; status used for context saving
- ; BSR_TEMP RES 1 ; bank select used for ISR context saving
- ;
- ;*******************************************************************************
- ; TODO PLACE VARIABLE DEFINITIONS GO HERE
- INT_VAR UDATA_ACS
- set0 RES 1
- set1 RES 1
- bit RES 1
- bit0 RES 1
- bit1 RES 1
- bit2 RES 1
- bit3 RES 1
- temp8 RES 1
- jauge RES 1
- conversion_result RES 1
- ;*******************************************************************************
- ; Reset Vector
- ;*******************************************************************************
- RES_VECT CODE 0x0000 ; processor reset vector
- GOTO START2 ; go to beginning of program
- ;*******************************************************************************
- ; TODO Step #4 - Interrupt Service Routines
- ;
- ; There are a few different ways to structure interrupt routines in the 8
- ; bit device families. On PIC18's the high priority and low priority
- ; interrupts are located at 0x0008 and 0x0018, respectively. On PIC16's and
- ; lower the interrupt is at 0x0004. Between device families there is subtle
- ; variation in the both the hardware supporting the ISR (for restoring
- ; interrupt context) as well as the software used to restore the context
- ; (without corrupting the STATUS bits).
- ;
- ; General formats are shown below in relocatible format.
- ;
- ;------------------------------PIC16's and below--------------------------------
- ;
- ; ISR CODE 0x0004 ; interrupt vector location
- ;
- ; <Search the device datasheet for 'context' and copy interrupt
- ; context saving code here. Older devices need context saving code,
- ; but newer devices like the 16F#### don't need context saving code.>
- ;
- ; RETFIE
- ;
- ;----------------------------------PIC18's--------------------------------------
- ;
- ; ISRHV CODE 0x0008
- ; GOTO HIGH_ISR
- ; ISRLV CODE 0x0018
- ; GOTO LOW_ISR
- ;
- ; ISRH CODE ; let linker place high ISR routine
- ; HIGH_ISR
- ; <Insert High Priority ISR Here - no SW context saving>
- ; RETFIE FAST
- ;
- ; ISRL CODE ; let linker place low ISR routine
- ; LOW_ISR
- ; <Search the device datasheet for 'context' and copy interrupt
- ; context saving code here>
- ; RETFIE
- ;
- ;*******************************************************************************
- ; TODO INSERT ISR HERE
- ;*******************************************************************************
- ; MAIN PROGRAM
- ;*******************************************************************************
- MAIN_PROG CODE ; let linker place main program
- check ;verification des bits pour une couleur d'une LED
- CALL send0
- CALL send0
- CALL send0
- CALL send0
- BTFSS bit, 3 ; on ne regarde que le bit 3 car on n'utilise que celui ci
- CALL send0 ;pour ne pas abuser de l'intensité des LED qui est donc fixé à 8
- BTFSC bit,3
- CALL send1
- CALL send0
- CALL send0
- CALL send0
- RETURN
- send0
- MOVLW b'00100000' ; on fixe la sortie RB5 a 1
- MOVWF LATB
- NOP
- NOP
- NOP
- MOVLW b'00000000' ; durant 0.32 u puis on remet a 0
- MOVWF LATB
- NOP
- NOP ; puis on fini les 1.25 u de la commande
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- RETURN
- send1
- MOVLW b'00100000' ; on fixe la sortie RB5 a 1
- MOVWF LATB
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- MOVLW b'00000000' ; durant 0.82 u puis on remet a 0
- MOVWF LATB
- NOP
- NOP
- RETURN
- sendlED
- MOVF bit3,0 ; on envoie une a une les commandes des couleurs de la LED
- MOVWF bit ; couleure verte
- CALL check
- MOVF bit2,0 ; couleure rouge
- MOVWF bit
- CALL check
- MOVF bit1,0 ;couleur bleu
- MOVWF bit
- CALL check
- MOVF bit0,0 ;couleur blanche
- MOVWF bit
- CALL check
- RETURN
- null ; liste de bit pour éteidnre les LED
- MOVLW b'00000000'
- MOVWF bit0
- MOVLW b'00000000'
- MOVWF bit1
- MOVLW b'00000000'
- MOVWF bit2
- MOVLW b'00000000'
- MOVWF bit3
- CALL sendLED
- RETURN
- red ; liste de bit pour afficher du rouge
- MOVLW b'00000000'
- MOVWF bit0
- MOVLW b'00000000'
- MOVWF bit1
- MOVLW b'00001000'
- MOVWF bit2
- MOVLW b'00000000'
- MOVWF bit3
- CALL sendLED
- RETURN
- yellow ; liste de bit pour afficher du jaune
- MOVLW b'00000000'
- MOVWF bit0
- MOVLW b'00000000'
- MOVWF bit1
- MOVLW b'00001000'
- MOVWF bit2
- MOVLW b'00001000'
- MOVWF bit3
- CALL sendLED
- RETURN
- green ;liste de bit pour afficher du vert
- MOVLW b'00000000'
- MOVWF bit0
- MOVLW b'00000000'
- MOVWF bit1
- MOVLW b'00000000'
- MOVWF bit2
- MOVLW b'00001000'
- MOVWF bit3
- CALL sendLED
- RETURN
- blue ;liste de bit pour afficher du bleu
- MOVLW b'00000000'
- MOVWF bit0
- MOVLW b'00001000'
- MOVWF bit1
- MOVLW b'00000000'
- MOVWF bit2
- MOVLW b'00000000'
- MOVWF bit3
- CALL sendLED
- RETURN
- analyse ; analyse des bits de commande pour les 8 LED d'une colonne
- BTFSS gauge, 0 ; commande pour la 1eme LED
- CALL null
- BTFSC gauge,0
- CALL blue
- BTFSS gauge, 1 ; commande pour la 2eme LED
- CALL null
- BTFSC gauge,1
- CALL blue
- BTFSS gauge, 2 ; commande pour la 3eme LED
- CALL null
- BTFSC gauge,2
- CALL green
- BTFSS gauge, 3 ; commande pour la 4eme LED
- CALL null
- BTFSC gauge,3
- CALL green
- BTFSS gauge, 4 ; commande pour la 5eme LED
- CALL null
- BTFSC gauge,4
- CALL yellow
- BTFSS gauge, 5 ; commande pour la 6eme LED
- CALL null
- BTFSC gauge,5
- CALL yellow
- BTFSS gauge, 6 ; commande pour la 7eme LED
- CALL null
- BTFSC gauge,6
- CALL red
- BTFSS gauge, 7
- CALL null
- BTFSC gauge,7 ; commande pour la 8eme LED
- CALL red
- RETURN
- reading ;lecture du tableau de valeurs enregistré
- MOVLW 0x1
- MOVWF PCLATH
- CLRF FSR0L
- MOVLW 0x01
- MOVWF FSR0H,0
- MOVF INDF0, 0, 0
- RLNCF WREG,0 ;décalage bit de gauche = *2
- CALL table
- MOVWF gauge ; recuperation de la valeur copié dans jauge
- CALL analyse
- RETURN
- loop_on_8_bit ; boucle pour les 8 colonnes de LED
- MOVLW 0x08
- MOVWF temp8
- LOOP8
- CALL reading
- INCF FSR0L,1
- DECFSZ temp8 ,1
- GOTO LOOP8
- RETURN
- write ; Ecriture du resultat de la conversion dans le tableau
- MOVF conversion_result, 0
- MOVWF POSTINC0
- RETURN
- result_treatement ; On recupere les 3 bits qui nous interesse : 5 à 7
- RRCF conversion_result ; On decale à droite 4 fois
- RRCF conversion_result
- RRCF conversion_result
- RRCF conversion_result
- MOVLW b'00000111'
- ANDWF conversion_result, 1 ; On fait un "ET" arithmetique pour ne garder que les 3 LSB
- RETURN
- ADC_launcher ; On lance le convertisseur analogique numerique
- MOVLW b'11000001'
- MOVWF ADCON0
- conversion_end ; On surveille le LSB de ADCON0 pour attendre la fin de la conversion
- BTFSC ADCON0, 0
- GOTO conversion_end
- MOVF ADRESH, 0 ; Le resultat est recupere dans ADRESH
- MOVWF conversion_result
- CALL result_treatement ; On traite le resultat pour obtenir 3 bits
- CLRF FSR0L,0 ; On initialise l'adresse du tableau
- MOVLW 0x01
- MOVWF FSR0H, 0
- CALL write ; On ecrit le resultat dans le tableau
- RETURN
- ADC_init_high_pitch ; Initialisation du channel pour les aigues
- CLRF ADPCH
- RETURN
- ADC_init_medium_high ; Initialisation du channel pour les medium hauts
- MOVLW b'00000001'
- MOVWF ADPCH
- RETURN
- ADC_init_medium_bass ; Initialisation du channel pour les medium bas
- MOVLW b'00000010'
- MOVWF ADPCH
- RETURN
- ADC_init_bass ; Initialisation du channel pour les basses
- MOVLW b'00000011'
- MOVWF ADPCH
- RETURN
- lets_convert ; On convertit les 4 signaux un par un
- CALL ADC_init_high_pitch ; d'abord les aigue
- CALL ADC_launcher ; et on lance la conversion
- CALL ADC_init_medium_high ; idem pour medium haut
- CALL ADC_launcher
- CALL ADC_init_medium_bass ; puis medium bas
- CALL ADC_launcher
- CALL ADC_init_bass ; et basse
- CALL ADC_launcher
- START2
- MOVLW b'00000000'
- MOVWF TRISB ; Les leds sont en sorties
- MOVWF conversion_result ; On initialise le resultat de conversion a 0
- CALL lets_convert ; On lance les conversion pour recuperer les 4 signaux
- CALL lets_shine ; On allume les leds
- table ADDWF PCL ; Donne un jauge permettant de savoir a quelle hauteur on allume les leds
- RETLW 0x00
- RETLW 0x01
- RETLW 0x03
- RETLW 0x07
- RETLW 0x0F
- RETLW 0x1F
- RETLW 0x3F
- RETLW 0x7F
- RETLW 0xFF
- GOTO $ ; boucle infinie
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement