jeanninemtv
Senior Member
Offline
Posts: 311
Thank You
-Given: 57
-Receive: 25
|
|
« on: April 26, 2009, 09:40:58 09:40 » |
|
Hello, i begin to try a little with 18f4550 after a lot of time.... i wrote some code and it worked IN ISIS, but at the moment to burn it .... no sucess at all.. for example, i wrote it and it worked: Device 18F4550 XTAL 20 ALL_DIGITAL true Declare PLL_REQ = OFF Declare LCD_RSPIN PORTB.3 Declare LCD_ENPIN PORTB.2 Declare LCD_DTPIN PORTD.4 Declare LCD_INTERFACE 4 Declare LCD_LINES 4 Declare LCD_COMMANDUS 4000' to 65535 microseconds (us). 'Time to wait (in microseconds) between commands sent to the LCD. If the DECLARE is not used in the program, then the default delay is 2000us (2ms). Declare LCD_DATAUS 100' to 255 microseconds (us). 'Time to wait (in microseconds) between data sent to the LCD. If the DECLARE is not used in the program, then the default delay is 50us.
Symbol TMR1IF = PIR1.0 ' TMR1 Overflow Interrupt Flag bit Symbol TMR2IF = PIR1.1 ' TMR2 to PR2 Match Interrupt Flag Symbol CCP1F = PIR1.2 ' CCP1 Interrupt Flag Symbol TXIF = PIR1.4 ' USART Transmit Interrupt Flag Symbol RCIF = PIR1.5 ' USART Receive Interrupt Flag Symbol CMIF = PIR1.6 ' Comparator Interrupt Flag Symbol EEIF = PIR1.7 ' EEPROM Write Operation Interrupt Flag Symbol RBIF = INTCON.0 ' RB Port Interrupt Flag Symbol INTF = INTCON.1 ' RB0 External Interrupt Flag Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag Symbol RBIE = INTCON.3 ' RB Port Change Interrupt Enable Symbol INTE = INTCON.4 ' RB0 External Interrupt Enable Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable Symbol PEIE = INTCON.6 ' Peripheral Interrupt Enable Symbol GIE = INTCON.7 ' Global Interrupt Enable Symbol TMR1IE = PIE1.0 ' TMR1 Overflow Interrupt Enable Symbol TMR2IE = PIE1.1 ' TMR2 to PR2 Match Interrupt Enable Symbol CCP1IE = PIE1.2 ' CCP1 Interrupt Enable Symbol TXIE = PIE1.4 ' USART Transmit Interrupt Enable Symbol RCIE = PIE1.5 ' USART Receive Interrupt Enable Symbol CMIE = PIE1.6 ' Comparator Interrupt Enable Symbol EEIE = PIE1.7 ' EE Write Complete Interrupt Enable Dim LOL As Byte PORTB_PULLUPS TRUE OVER_INTERRUPT: LOL=0 TRISB=%11110011'$FF TRISC=%11111111 TRISD=%00000000 DelayMS 250 Cls ECRAN_PREUVE: ' 00000000011111111112 ' 12345678901234567890 Print At 1,1,"tps:00:00 tpp:00:00" Print At 2,1,"#tr:00:00 dtps:00:00" Print At 3,1,"tr/mn: 00000 " Print At 4,1,"V: 00000 T: 000.00" Set PORTD.1 NADA:
Print At 4,1,"V: 00000 T: 000.00"
DelayMS 250 GoTo NADA End
after that i thought to put to work portb change interrupts to manage 4 buttons, i have some ideas, but the problem is not that, i tried to put more code and lcd become crazy! numbers are mixed and nothing understable is shown NOTE, i disabled interrupts , i just tested if after press button rb0 next screen is shown a this moment, and no success!! Device 18F4550 XTAL 20 Declare PLL_REQ = OFF ALL_DIGITAL TRUE Declare LCD_RSPIN PORTB.3 Declare LCD_ENPIN PORTB.2 Declare LCD_DTPIN PORTD.4 Declare LCD_LINES 4 ADIN_RES=10 ' --- resolucion ADIN_STIME=100 ' --- tiempo de adquisicion ADIN_TAD= frc ' Allow 100us for charge time Symbol CCP1F = PIR1.2 ' CCP1 Interrupt Flag Symbol CMIF = PIR1.6 ' Comparator Interrupt Flag Symbol EEIF = PIR1.7 ' EEPROM Write Operation Interrupt Flag Symbol RBIF = INTCON.0 ' RB Port Interrupt Flag Symbol INTF = INTCON.1 ' RB0 External Interrupt Flag Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag Symbol RBIE = INTCON.3 ' RB Port Change Interrupt Enable Symbol INTE = INTCON.4 ' RB0 External Interrupt Enable Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable Symbol PEIE = INTCON.6 ' Peripheral Interrupt Enable Symbol GIE = INTCON.7 ' Global Interrupt Enable Symbol TMR1IE = PIE1.0 ' TMR1 Overflow Interrupt Enable Symbol TMR2IE = PIE1.1 ' TMR2 to PR2 Match Interrupt Enable Symbol CCP1IE = PIE1.2 ' CCP1 Interrupt Enable Symbol ADIE = PIE1.6 ' Comparator Interrupt Enable Symbol EEIE = PIE1.7 ' EE Write Complete Interrupt Enable Symbol TMR1IF = PIR1.0 ' TMR1 Overflow Interrupt Flag Symbol TMR2IF = PIR1.1 ' TMR2 to PR2 Match Interrupt Flag Symbol CCP1IF = PIR1.2 ' CCP1 Interrupt Flag Symbol SSPIF = PIR1.3 ' Synchronous Serial Port (SSP) Interrupt Flag Symbol TXIF = PIR1.4 ' USART Transmit Interrupt Flag Symbol RCIF = PIR1.5 ' USART Receive Interrupt Flag Symbol ADIF = PIR1.6 ' A/D Converter Interrupt Flag Symbol PSPIF = PIR1.7 ' Parallel Slave Port Read/Write Interrupt Flag Symbol relay_1 = PORTD.3 ' relai du marche-arrete general... Symbol relay_2 = PORTD.2 ' relai du klaxon... Dim pos_cur As Byte Dim raw As Word ' variable de prueba Dim testi As Byte Dim temp_moteur As Float Dim tck As Byte ' contador para el tiempo base del reloj. Dim tcks As Byte ' contador de base para cada segundo.. 200 en tmr2 me dio aprox 1 segundo Dim min1 As Byte Dim min2 As Byte Dim sec1 As Byte Dim sec2 As Byte Dim ch0_val As Word Dim ma As Bit Dim dejapasse As Bit Dim flag_buttonA As Bit Dim flag_buttonB As Bit Dim flag_klaxon As Bit Dim flag_restore As Bit Dim flag_tim1 As Bit Dim tmp_portb As Byte Dim m_total As Byte Dim s_total As Byte Dim m_partiel As Byte Dim s_partiel As Byte Dim m_dernier As Byte Dim s_dernier As Byte Dim m_best As Byte Dim s_best As Byte Dim f_tmp As Word Dim freq_hall1 As word Dim freq_hall2 As float Dim nro_tours As Byte
PORTB_PULLUPS TRUE ON_INTERRUPT GoTo INTERRUPT_ROUTINE 'hardware interrupt GoTo OVER_INTERRUPT INTERRUPT_ROUTINE: Context SAVE ' Only needed for 16 bit devices If INTF = 1 Then GoTo R_MARCHE_ARRETE EndIf If TMR2IF = 1 Then GoTo R_HORLOGE_PRINCIPAL EndIf If RBIF = 1 Then GoTo R_BOUTONS EndIf '********************************** interruption du timer... ************************** R_HORLOGE_PRINCIPAL: TMR2=0 PR2=190'5 ' 200 da 1 segundo 50 da 250 mili tck=tck+1 ' 'aqui va rutina de display de vueltas!! ' If tck=100 Then tcks=tcks +1 Toggle PORTD.1 sec1=sec1+1 If sec1=60 Then sec1=0 min1=min1+1 EndIf sec2=sec2+1 If flag_buttonB=1 Then nro_tours=nro_tours+1 m_dernier=min2 s_dernier=sec2 sec2=0 min2=0 Clear flag_buttonB EndIf If sec2=60 Then sec2=0 min2=min2+1 EndIf tck=0 EndIf TMR2IF=0 Context Restore '++++++++++++++++++++++++++++++++++++++++++ R_MARCHE_ARRETE: dejapasse=0 If ma=0 Then ma=1 relay_1=1 Set RBIE Else ma=0 relay_1=0 Clear RBIE
EndIf INTF=0 Context Restore R_BOUTONS: tmp_portb=PORTB tmp_portb=tmp_portb >> 4 tmp_portb=tmp_portb & $0F '***************** RUTINA DEL CLAXON, SOLO DURA CUANDO PRESIONAS ********************* If tmp_portb = %00001111 And testi=%00001101 Then Clear flag_klaxon Clear relay_2 EndIf '************************************************************************************* 'boton A, comienza la cuenta.... If tmp_portb = %00000111 Then If flag_buttonA=0 Then Set flag_buttonA Set TMR2IE Else Clear flag_buttonA Clear TMR2IE min1=0 : sec1=0 : min2=0 : sec2=0 : nro_tours=1 EndIf testi=tmp_portb EndIf '************************************************************************************* If tmp_portb = %00001011 Then If flag_buttonB=0 Then Set flag_buttonB EndIf testi=tmp_portb EndIf If tmp_portb = %00001101 Then Set flag_klaxon Set relay_2 testi=tmp_portb EndIf If tmp_portb = %00001110 Then Set flag_restore testi=tmp_portb EndIf RBIF=0 Context Restore '********************************** PROGRAMA NORMAL ... ************************** OVER_INTERRUPT: 'etat initial des variables: raw=0 : tck=0 : ma=0 : dejapasse=0 'CONFIG DU CH0 DU ConvertisseurAnalogue/Numerique: TRISA= $01 ' Setup PORTA.0 as an input ADCON1 = %10001110 'CONFIG OF PORTX
TRISB=$FF TRISC=0 TRISD=0 TRISE=0 PORTB=0 PORTA=$FF PORTC=0 PORTD=0 flag_buttonA=0 flag_buttonB=0 flag_klaxon=0 flag_restore=0 nro_tours=1 Cls ' écriture de caracteres dans le CGRAM du afficheur LCD. ' Print $FE,$40,$1e,$1e,$10,$00,$1F,$15,$15,$00 '0 tpm ' Print $FE,$48,$00,$0C,$12,$12,$0C,$00,$00,$00 '1 degrees ' Print $FE,$50,$00,$0E,$1F,$1F,$1F,$0E,$00,$00 '2 ' Print $FE,$58,$00,$0E,$11,$11,$11,$0E,$00,$00 '3 ' Print $FE,$60,$08,$1D,$08,$09,$0C,$00,$1F,$00 '4 ' Print $FE,$68,$00,$0A,$0A,$0A,$00,$0E,$11,$00 '5 ' Print $FE,$70,$11,$1B,$15,$11,$11,$00,$1F,$00 '6 motor ' Print $FE,$78,$1F,$00,$0E,$15,$1F,$15,$0E,$00 '7 ruedita
'CONFIG DES INTERRUPTS Init: 'configuration de l'interrupt du timer2 T2CON = %01111111 ' Set T2CON.2 TMR2IF=0 TMR2IE=0 TMR2=0 PR2=190'5 INTCON=$C0 ' set GIE and PEIE bits %110000000 'configuration de l'interrupt du RB0/int INTE=1 testi=$0F main_loop: If ma=1 Then GoTo screen_activate EndIf screen_disabled: If dejapasse=0 Then Cls dejapasse=1 EndIf ' 00000000011111111112 ' 12345678901234567890 Print At 1,3," " Print At 2,1," Press M/A " Print At 3,1," " Print At 4,4," " raw=0 : tck=0 : tcks=0 : min1=0 : sec1=0
lala:
delayms 2000
''*---------------------------------------------
'1234567890 123 456789 0 Print At 1,1," : t "," "," "," C" ' Outp ut ' 1 23456789 10 12 13 14 15 16 17 18 19 20 Print At 2,1," : t"," " '',$3,$3,$3,$3,$3,$3,$3,$3 ' 12345678901234567890 Print At 3,1,"tp: : tt: :" Print At 4,1,"tour: td: :"
''*--------------------------------------------- goto lala
GoTo main_loop
screen_activate: If dejapasse=1 Then GoTo loop_001 EndIf screen_main: Cls dejapasse=1 ' 00000000011111111112 ' 12345678901234567890 ' Print At 1,1,"tps:00:00 tpp:00:00" ' Print At 2,1,"#tr: dtps:00:00" ' Print At 3,1," RPM : 00000" ' Print At 4,1,"V: 00000 T:"
' 1 2345678 9 0123 4 5 6 7 8 90 Print At 1,1,": t"," "," "," C" ' Outp ut ' 1 23456789 10 12 13 14 15 16 17 18 19 20 Print At 2,1,": t"," "',$3,$3,$3,$3,$3,$3,$3,$3 ' 12345678901234567890 Print At 3,1,"tp: : tt: :" Print At 4,1,"tour: td: :"
loop_001: nop NADA:
'***************** ACONDICIONAMIENTO DEL SENSOR DE TEMPERATURA *********************** raw=ADIn 0 raw= raw * 5 temp_moteur = raw/ 1023 'mV If temp_moteur > 2.6 Then temp_moteur= temp_moteur - 2.368 Else temp_moteur= temp_moteur - 2.315 EndIf temp_moteur= temp_moteur * 140.5'255 / 1.815 '************************************************************************************* f_tmp= Counter PORTC.1 , 500 freq_hall1 = f_tmp * 120 f_tmp= Counter PORTC.2 , 450 DelayMS 35 freq_hall2 = f_tmp * 1.26 Print At 1,3,DEC4 freq_hall1 Print At 2,3,DEC1 freq_hall2 'Cursor 4,14 ' If temp_moteur < 10 Then ' Print "00"',DEC1 temp_moteur ' GoTo suiv2 ' EndIf ' If temp_moteur < 100 Then ' Print "0"',DEC1 temp_moteur ' GoTo suiv2 ' EndIf 'If temp_moteur > 99 Then 'Print At 4,14',DEC1 temp_moteur 'EndIf 'suiv2: ' Print DEC1 temp_moteur 'AFFICHAGE DES PARAMETRES --> TEMPS.... Print At 3,4,DEC2 min2 Print At 3,7,DEC2 sec2 Print At 3,14,DEC2 min1 Print At 3,17,DEC2 sec1 Print At 4,6,DEC2 nro_tours Print At 4,14,DEC2 m_dernier Print At 4,17,DEC2 s_dernier
'Print At 4,5,BIN4 testi' prueba de status de los botones de control 'colocar logica del sistema cronometro aqui....
GoTo main_loop End
I THINK ITS SOMETHING WRONG WITH FUSES, I REALLY DONT KNOW I AM DELETTING PARTS TO VIEW IF IT WORKS AND NOTHING HAPPEN... Posted on: April 26, 2009, 10:38:56 10:38 - Automerged
BTW, i'm using pds 3.2.5.5 integrated with mplab prior to use icd2 programmer
|