Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

USART interrpt in PIC16F877A

Status
Not open for further replies.

amindzo

Member
Hi,
i have enabled USART interrupt in pic16f877a and it's interrupt work but other part of my program doesn't work.
im my program i read keyboard and when interrpt is coming it show the recieved data on lcd.
when serial data is coming the progran goes to interrupt and shoew the recieved data on lcd but reading keyboard doesn't work.
just the interrupt program is working.when i push the keys the program should show the number on lcd but it doesn't work and when i disable interrupt the keyboard program is working.
i enabled USART interrup like this:
on interrupt goto USART_int
INTCON = %11000000 'Initializing the INTCON register
PIE1= %00100000 'Initializing the PIE1 register
RCSTA= %11010011
and use this instruction :
serin PORTC.7,N1200,["A"],y1

could you help me?
what should i do?
maby i have a problem in my program.
i use micro code studio picbasic pro2.41



this is my program:

define OSC 4
include"modedefs.bas"
ADCON1=7 ' convert porta from analoge to digital
TRISA = %00000000 ' set porta as an output
TRISB = %00001111 'set first 4 bit of portb as an input and last 4 bit as putput
TRISC = %00000000 ' set portc as output
'----------------------------------------------------
' Define LCD parameters
' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTD
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
'----------------------------------------------
y1 var byte
y2 var byte
y3 var byte
'-------------------------------------------------
on interrupt goto USART_int
INTCON = %11000000 'Initializing the INTCON register
PIE1= %00100000 'Initializing the PIE1 register
RCSTA= %11010011
'------------------------------------------------



scanning keyboard:


''program



goto scanning keyboard

USART_int:
disable
USART_int:
serin PORTC.7,N1200,["A"],y1
serin PORTC.7,N1200,["A"],y2
serin PORTC.7,N1200,["A"],y3
'
if (y2=y3) then
lcdout $fe,1,#y2
pause 4000
lcdout $fe,1
PORTC.4=1
pause 4000
PORTC.4=0
endif
INTCON = %11000000
PIE1= %00100000
RCSTA= %11010011
resume
enable
end
delay:
for i=1 to 2000
pause 1
next i
return
 
RE: Interupt

Hi there,

It maybe that you are running the PIC clock a little to slow.

When the interrupt happens it takes a number of clock cycles to jump to the ISR (Interrupt Service Routine). During that time it maybe that the data sent by the keyboard has already been sent before the Pic has even got into the ISR.

This is also dependent on how you have the interrupt setup.

How big are the data packages from the keyboard?

How do you have the interrupt configured?

Once we know people may be able to help

All the best

Pete

Phazersoft@hotmail.co.uk
 
your code is incomplete.
You should use HSERIN instead of SERIN
you never set the according USART DEFINE ... look in the HSERIN section of your book.
You really should update your PBP to the latest 2.47 version.
You're lucky if some part works.

Being said, post your schematic and your whole code here.

also...
Code:
serin PORTC.7,N1200,["A"],y1
serin PORTC.7,N1200,["A"],y2
serin PORTC.7,N1200,["A"],y3
At least your PC or external hardware must send... somthing like A1A2A3 in one shot, case else, your program will end up in an endless loop and just return to your ISR each you receive a single character... what i suspect...
Code:
TRISC = %00000000 ' set portc as output
your lucky that SERIN set the according pin to input... but it's weird that some interrupt may work by setting the USART input to output :)
 
Last edited:
Hi,
the program that i show you befor is an example but my main prigram is this that it is vey long.
about my hardware i connected keyboard to PORTB(row to RB0 to RB3 and
columns RB4 to RB7) and connect the RB0 to RB3 a 10k resister and i set the columns to 1 and read the rows rapidly to find which key is pushed.
i connected the DS1307 to RA0 and RA1(SDA to RA0 and SCL to RA1).
my program is about the reviever of a wireless weather station.
in my program i use haming codes to find and correct errors.
i connect a RF reciever to PORTC.7 but i my program it is on PORTA.5 that i corrert it in my harware and my software.
my program is very long abpot 1000 lines that i can't put it here and my keyboard program is long too and it has alot of subrotins.
what's the difference between serin and hserin instructions?


please help me
 
Last edited:
Hi,
when i write a simple program to turn on and off a led, it deosn't work too.
but it takes the seial data and show on lcd.
after i disable interrupt the led working.
i think i have problem to initialize the RCSTA register.
by changing the value of this register it led works but serial data is not show on lcd.
i don't know what should i do?
help me.
i have iniatilized it like this now:
RCSTA= %11010000
I trsnmit data with 8 bit data-no parity-one stop bit
how should i intialize the RCSTA register in reciever?
should i inirialize TXSTA register in the reciever ?
 
Last edited:
Hi,
i write my program with ondebug goto instruction too but i have a same problem.in this case just interrupt rotine just work and other part of my program doesn't work.
what's the reason?
 
can i use RB0 interrupt instead of USART?
for example i enable RB0 interrupt for falling edge and send 10101010....
for about five bytes and then send my data from transmitter and when RF reciever transfer it to micro then the interrupt happen and goes to interrupt rotine to get serial data with serin instruction(in interrup rotine).
is it a good idea?
 
Last edited:
Hi,
i enabled RB0 interrupt it works but my problem didn't solve.i have a same problem as i had in
USART interrupt.
in RB0 interrupt also just interrupt routine works and other part of my program don't work.
i write a simple program to turn on and off led and when serial data is coming the RB0 interrupt
occur (because i send 10101010 befor my data) .
so when serial data is coming the program goes to interrupt routine and show the revieved data on lcd but led doen't turn on or off.
just interrupt routine works.
what's the reason?
i have a same problem in USART interrupt too.
i use micro code studio picbasic pro2.41

this is my simple program:


define OSC 20
include"modedefs.bas"
ADCON1=7 ' convert porta from analoge to digital
TRISA = %00000000 ' set porta as an output
TRISB = %00001111 'set first 4 bit of portb as an input and last 4 bit as putput
TRISC = %00000000 ' set portc as output
'----------------------------------------------------
' Define LCD parameters
' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTD
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1
i var word
y1 var byte
y2 var byte
y3 var byte

on interrupt goto int
OPTION_REG = %10000000
INTCON = %10010000
TRISB = %11111111
start:
for i=1 to 1000
PORTC.3=0
pause 1
next i
for i=1 to 1000
PORTC.3=1
pause 1
next i
goto start
disable
int:
serin PORTB.0,N1200,["A"],y1
serin PORTB.0,N1200,["A"],y2
serin PORTB.0,N1200,["A"],y3
'
if (y2=y3) then
lcdout $fe,1,#y2
pause 4000
lcdout $fe,1
PORTC.4=1
pause 4000
PORTC.4=0
endif
OPTION_REG = %10000000
INTCON = %10010000
resume
enable
end
 
Hi,
i found that two interrupts(USART and RB0) are working and when i turn on micro it goes to interrupt routine.
for RB0 i should connect a pull up resistor but when i connect the out put of the RF reciever to it interrupt occurs.
i don't know why?
maby the noise of RF reciever (when we don't have data) is the reason.
for USART interrupt ,i have the same problem but in this case , there is no deference between connecting and not connecting the RF reciever.
when i turn on micro it goes to interrupt routine.
what is the reason?
what should i do?
 
I would be happy to make an effort to analyse your code if you make an effort to format it correctly to make it easier to read.

Mike
 
Hi,
i can solve my problem. it works but i have another problem.when i use this interrupt with a simple program it works but when i use this in a big one(my program is about 1000 lines) it doesn't work.
i also use 20M crystal but it doesn't work too.
what's the reason?
 
if it works in a simple program, use it as a template, and build the code slowly to catch if its a compiler or source code error.
 
Hi,
my program was overed from 1800h addres.maby my problem is code crosses boundary.should i seprcify my interrupt routine is in which bank?
(but i think in basic it's not needed)
 
Hi,
maby i found the problem about USART interrupt.i read keyboard by polling method so my program is in alot of conditional instructions so serial sata is coming and my keyboard program is in conditional instruction so it can't go to interrupt routine.
could you tell me what should i do?
 
amindzo said:
Hi,
maby i found the problem about USART interrupt.i read keyboard by polling method so my program is in alot of conditional instructions so serial sata is coming and my keyboard program is in conditional instruction so it can't go to interrupt routine.
could you tell me what should i do?

The whole point of an interrupt routine is that it 'interrupts', so the interrupt should cause the program to leave what it's doing and execute the interrupt rourine.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top