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.

How to enable USART interrupt in PIC16F873A

Status
Not open for further replies.

amindzo

Member
Hi,
I want to read keyboard and show the numbers on lcd by pushing any number and also i want to recieve
serial data from an RF module so i have to enable interrupt.
How can i do it?
i use a PIC16F873A.
i have written a program that you can see here .i think i have problem with my program.
could youb help me with this?

i use micro code studio picbasic pro2.41

Program:
define OSC 4
include"modedefs.bas"
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' 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 word
y2 var word
y3 var word
ADCON1=7
start:
on interrupt goto int
INTCON = %11000000
PIE1= %00100000

TRISB = %00001111
portb.5=1
if portb.1=1 then
lcdout $fe,1,"1"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"4"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"7"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"prog"
call delay
endif
portb.5=0
portb.6=1
if portb.1=1 then
lcdout $fe,1,"2"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"5"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"8"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"0"
call delay
endif
portb.6=0
portb.7=1
if portb.1=1 then
lcdout $fe,1,"3"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"6"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"9"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"mode"
call delay
endif
portb.7=0
goto start
disable
int:
serin PORTA.0,N1200,["A"],y1
serin PORTA.0,N1200,["A"],y2
serin PORTA.0,N1200,["A"],y3
'
if (y2=y3) then
lcdout $fe,1,#y2
pause 4000
lcdout $fe,1
pause 4000
endif
INTCON = %11000000
PIE1= %00100000
resume
enable
end
delay:
for i=1 to 400
pause 1
next i
return
 
You have to set the USART Interrupt Enable Bit
You have to set the Global Interrupt Enable Bit
You have to place some code at the interrupt location (typically 0x0004 for the mid-range pic series) to check for the USART Interrupt Flag and process accordingly.
 
I don't know the version of BASIC you are using but I think your problem may be the use of the serin command in the IRQ. As you are using the hardware USART, you should read 1 byte in the IRQ from RCREG and clear the RCIF bit.
HTH

Mike.
 
Hi,
I have enabled USART interrupt.
I want to reading keyboard and when you push a key the number shuld show on lcd.
after coming interrupt the USART interrupt,the serial information should shoe on lcd for 4 second and led that connected to PORTA.1 should on for 4 second.
lcd is not working but LED is turned on for 4 second.
and also the reading keyboard program doesn't work and with pushing any key you can't see anything on lcd
when i enable USART interrupt it works on pin that i use fr reciving serial dada in serin instruction.
couldyou help me with this problem?

this is my program:
define OSC 4
include"modedefs.bas"
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' 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 word
y2 var word
y3 var word
ADCON1=7
TRISA=0
PORTA.1=0
start:
on interrupt goto int
'OPTION_REG = %10000000
INTCON = %11000000
PIE1= %00100000
RCSTA= %11010000

TRISB = %00001111
portb.5=1
if portb.1=1 then
lcdout $fe,1,"1"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"4"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"7"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"prog"
call delay
endif
portb.5=0
portb.6=1
if portb.1=1 then
lcdout $fe,1,"2"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"5"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"8"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"0"
call delay
endif
portb.6=0
portb.7=1
if portb.1=1 then
lcdout $fe,1,"3"
call delay
endif
if portb.2=1 then
lcdout $fe,1,"6"
call delay
endif
if portb.3=1 then
lcdout $fe,1,"9"
call delay
endif
if portb.4=1 then
lcdout $fe,1,"mode"
call delay
endif
portb.7=0
goto start
disable
int:
serin PORTA.5,N1200,["A"],y1
serin PORTA.5,N1200,["A"],y2
serin PORTA.5,N1200,["A"],y3
'
if (y2=y3) then
lcdout $fe,1,#y2
pause 4000
lcdout $fe,1
PORTA.1=1
pause 4000
PORTA.1=0
endif
INTCON = %11000000
PIE1= %00100000
'RCSTA= %11010000
resume
enable
end
delay:
for i=1 to 400
pause 1
next i
return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top