PDA

View Full Version : Serin and TMR0



capitano
- 14th December 2004, 23:14
It's possible use Serin command and TMR0 interrupt in the same program ?

mister_e
- 15th December 2004, 02:10
why not??? the only thing you have to care about IMO, is to disable interupts before using SERIN.

capitano
- 15th December 2004, 19:25
My program must turn on 64 led connected to PIC with 4 mux 74HC154

This is my program but it don't work fine, i try to disable interrupt but ...



DEFINE OSC 4 'Definisco fre. osc. quarzo

' *****************************
' LIBRERIE

Include "modedefs.bas"

' ************************************
' IMPOSTA PORTE

TRISA = 0 ' Imposto la porta A come uscita
TRISB =%10000000 ' Imposto la porta B come uscita
OPTION_REG=%11010001

PIE1=%00000000
ADCON1=%00000111

' ************************************
'VARIABILI

TX var PORTB.6
RX var PORTB.7
Mode var PORTB.5

EN1 VAR PORTA.0
EN2 VAR PORTA.1
EN3 VAR PORTA.2
EN4 VAR PORTA.3

x var byte ' Definizione variabile tipo byte
k var byte
j var byte
led1 var byte
led2 var byte
stato var bit[64]
pos var byte



high EN1
high EN2
high EN3
high EN4

for k=0 to 63
stato[k]=0
next k


INTCON = %11100000

ON INTERRUPT GoTo interr



' **************************************
'PROGRAMMA PRINCIPALE



mainloop: 'label



intcon.5=0

SERIN RX,T9600,pos

intcon.5=1

stato[pos]=1 -----------------> Active led a position pos



GoTo mainloop ' ritorna allla label iniziale






'***********************
'GESTIONE DI INTERRUPT

Disable

interr:


'*********************
'Interrupt TMR0 -------------->>>' Routine to scan all 64 led
I can't interrupt it

If INTCON.2=1 then


for x=0 to 15

if stato[x]=1 then

portb.0=x.0[3]
portb.1=x.0[2]
portb.2=x.0[1]
portb.3=x.0[0]


low EN1
high EN2
high EN3
high EN4

pause 1
endif

next x


high EN1
high EN2
high EN3
high EN4


for x=0 to 15

j=x+16

if stato[j]=1 then

portb.0=x.0[3]
portb.1=x.0[2]
portb.2=x.0[1]
portb.3=x.0[0]


high EN1
low EN2
high EN3
high EN4

pause 1
endif

next x



high EN1
high EN2
high EN3
high EN4

for x=0 to 15

j=x+32

if stato[j]=1 then

portb.0=x.0[3]
portb.1=x.0[2]
portb.2=x.0[1]
portb.3=x.0[0]


high EN1
high EN2
low EN3
high EN4

pause 1
endif

next x

high EN1
high EN2
high EN3
high EN4

for x=0 to 15

j=x+48

if stato[j]=1 then

portb.0=x.0[3]
portb.1=x.0[2]
portb.2=x.0[1]
portb.3=x.0[0]


high EN1
high EN2
high EN3
low EN4

pause 1
endif

next x

high EN1
high EN2
high EN3
high EN4


INTCON.2=0
endif



Resume
Enable






thank you in advance for your availability and excuse me for my english

Christian

NavMicroSystems
- 18th December 2004, 19:30
Christian,

what does your schematic look like?

regards

Ralph

klokan
- 16th May 2006, 01:19
I am using a PIC16F88 with external resonator of 4Mhz.

4 leds connected to portb pins and they are flashing in random in time with the internal timer1 and interrupt.

I have a 433mhz transmitter on another device sending :
serout rfmod,baud,[qual, dataout] ' qual = 10 and dataout = 11

I am not sure how to set the serin command on portb.3 to look for an interrupt of receiving this serial data, once received it should turn of a select led on the portb pin.

Any ideas ? or help appreciated please.

Thanks

yaskolo
- 16th May 2006, 14:20
i am using tmr0 interrupt in picbasic.
when i use pause,pulsin or serin command interrupt is not work correctly. can you help me for this. how can i use interrupt correctly with serin and pause.
or if i use asm interrupt code is it work ?.

thanks

mister_e
- 17th May 2006, 14:58
Those statement you said must be terminated prior to jump to interrupt routines. Using loop of short PauseUs, Using internal USART, create your own PULSIN statement will help.

Now it depend of your skill level. Usually i don't use PULSEIN, but i use an internal TIMER in counter mode (something like RA4 T0CKIN) with a PAUSE (or pause loop). Same for Usart. Sure that's a bit harder but save a huge amount of codespace. Maybe, i said maybe, Darrel's instant interupt may be of help but i'd never test them.

Even in assembler, SERIN, PAUSE, PULSEIN, should be terminated prior to jump to an interrupt handler. IMHO so far...