' PROGRAMA QUE USA INTERRUPCIONES INSTANTÁNEAS '
' INT_INT -- INT External Interrupt
' RBC_INT -- RB Port Change Interrupt
' TMR0_INT -- TMR0 Overflow Interrupt 16F
' TMR1_INT -- TMR1 Overflow Interrupt
' TMR2_INT -- TMR2 to PR2 Match Interrupt
' TX_INT -- USART Transmit Interrupt
' RX_INT -- USART Receive Interrupt
' CMP_INT -- Comparator Interrupt
' EE_INT -- EEPROM/FLASH Write Operation Interrupt
' BUS_INT -- Bus Collision Interrupt
' PSP_INT -- Parallel Slave Port Read/Write Interrupt
' AD_INT -- A/D Converter Interrupt
' SSP_INT -- Master Synchronous Serial Port Interrupt
' CCP1_INT -- CCP1 Interrupt
' CCP2_INT -- CCP2 Interrupt
clear
define OSC 16
' Define LCD connections
DEFINE LCD_DREG PORTD ' LCD Data Port
DEFINE LCD_DBIT 4 ' Starting Data Bit
DEFINE LCD_RSREG PORTD ' Register Select Port
DEFINE LCD_RSBIT 2 ' Register Select Bit
DEFINE LCD_EREG PORTD ' Enable Port
DEFINE LCD_EBIT 3 ' Enable Bit
DEFINE LCD_BITS 4 ' Data Bus Size
DEFINE LCD_LINES 2 ' Number of Lines on LCD
' Define RS232 line
DEFINE HSER_BAUD 19200 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
DEFINE HSER_SPBRG 51 'Hser spbrg init
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 24h 'Hser transmit status init
ADCON1 = 7 'Set portA outputs to Digital / No ADC
LCDOUT $FE,1 ' Initialize LCD
PAUSE 200
fase_a var portb.0
subir var portb.1
bajar var portb.2
prog var portb.3
salida var porta.0
'sentido var porta.1
'prueba var porta.2
aux_subir var ppp.0
aux_bajar var ppp.1
aux var ppp.2
escribir_inicio var ppp.3
escribir_pulso var ppp.4
ppp var byte
cuenta var word
pulso var word
inicio var word
que_escribir var word
aux_aux var byte
tmp var byte
direccion var byte
char var byte
cadena var byte[20]
i var byte
INCLUDE "DT_INTS-14.bas" ' Required
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines
TRISA = 0
PORTA = 0
TRISB = $FF
TRISC = %10000000
TRISD = 0
PORTD = 0
PORTC = 0
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _Int_RB0, PBP, yes
INT_Handler RX_INT, _Int_RX, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE INT_INT ; enable external (INT) interrupts
INT_ENABLE RX_INT ;
ENDASM
OPTION_REG = OPTION_REG & $80 | 1 ; Set TMR0 Prescaler to 256, leave RBPU alone
Main:
i = 0
cuenta = 0
aux_aux = 0
inicio = 300
pulso = 300
'Reinicializar variables
if subir and bajar then
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
endif
'Si no hay nada en eeprom graba variables
read $0,tmp
if tmp = $FF then
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
endif
'Se releen las variables
gosub leer
prog_: 'lazo principal
if subir and prog and not aux_subir then
gosub mod_inicio_subir
endif
if bajar and prog and not aux_bajar then
gosub mod_inicio_bajar
endif
if subir and not prog and not aux_subir then
gosub mod_pulso_subir
endif
if bajar and not prog and not aux_bajar then
gosub mod_pulso_bajar
endif
if not subir then
aux_subir = 0
endif
if not bajar then
aux_bajar = 0
endif
'salida por LCD
lcdout $fe,2
lcdout "Posicion ",dec4(cuenta)
lcdout $fe,$C0
lcdout "Inicio ",dec4(inicio)
lcdout $fe,$94
lcdout "Pulso ",dec4(pulso)
lcdout $fe,$d4
cadena[I] = char
LCDOUT STR cadena,20 'no aparece nada (nothing appears in lcd
' lcdout "Salida ",bin salida
goto prog_
'Subrutinas
leer:
INTCON = $00
read $0,inicio.byte1
Read $1,inicio.byte0
read $2,pulso.byte1
Read $3,pulso.byte0
INTCON = $90
RETURN
escribir:
if escribir_inicio = 1 then
que_escribir = inicio
direccion = $0
endif
if escribir_pulso = 1 then
que_escribir = pulso
direccion = $2
endif
' porta.2 = 1 'chequeo para saber que ha escrito en eeprom
Write direccion,(que_escribir.byte1)
write direccion+1,(que_escribir.byte0)
porta.2 = 0
return
mod_inicio_subir:
inicio = inicio + 15
aux_subir = 1
if inicio >= 3000 then
inicio = 3000
endif
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
return
mod_inicio_bajar:
inicio = inicio - 15
aux_bajar = 1
if inicio <= 50 then
inicio = 50
endif
escribir_inicio = 1
gosub escribir
escribir_inicio = 0
return
mod_pulso_subir:
pulso = pulso + 15
aux_subir = 1
if pulso >= 3000 then
pulso = 3000
endif
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
return
mod_pulso_bajar:
pulso = pulso - 15
aux_bajar = 1
if pulso <= 50 then
pulso = 50
endif
escribir_pulso = 1
gosub escribir
escribir_pulso = 0
return
'---[INT - interrupt handler]---------------------------------------------------
Int_RB0:
cuenta = cuenta + 1
if cuenta >= inicio then
salida = 1
endif
if cuenta >= (pulso + inicio) then
salida = 0
cuenta = 0
endif
@ INT_RETURN
'---[TMR0 - interrupt handler]-------------------------------(Blinky Light)-----
'T0Count Var WORD
'ToggleLED2: 'aprox 1 segundo
' T0Count = T0Count + 1
' if T0Count = 512 then T0Count = 0 : Toggle LED2
'@ INT_RETURN
'---[RX - inmterrupt handler]--------------------------------------------------
Int_RX:
PORTA.1 = 1 'to check RX int has come
i = i +1
hserin [char]
@ INT_RETURN
------------------------
questions:
Why LCD doesn´t display cadena?
Why when i entry many chars by rs232 (fast) variables inicio and pulso corrupts and display an abnormal value?? This check was made without int_int interrupts (fase_a it´s an output from a incremental encoder, and this one was stopped).
Thanx, and sorry if i´m 'heavy'.
Bookmarks