Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Interupt 16f887, 20MHz

Status
Not open for further replies.

tvojmuc

Newbie level 4
Joined
Sep 5, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
OK..I'm beginner so please be gently :oops:

How to use interrupt:
I have 16f887 PIC
BCD decoder on D0,1,2,3 and 4 led on B0,1,2,3
With interrupt routine I would like to read BCD code and then turn on LED
my code: -> and is not working:)

Code:
program LIGHT

 dim pre as byte


sub procedure interrupt ' Interrupt routine
'PORTE.0 = 1     'just to see int
'delay_ms(500)
pre =  PORTD
'PORTE.0 = 0       'just to see int
'delay_ms(500)
TMR0 = 155              ' Timer0 (or counter) returns its initial value
INTCON = 0x20           ' Bit T0IE is set, bit T0IF is cleared
end sub


main:
OPTION_REG = 0x04       ' Prescaler (1:32) is assigned to Timer0
TMR0 = 155              ' Timer0 counts from 155 to 255
INTCON = 0xA0           ' Enable interrupt on TMR0 overflow
TRISB = %00000000    'output = 0
TRISD = %11111111    'input = 1
TRISE.0 = 0          'output = 0
TRISE.1 = 0          'output = 0
zacetek:
PORTE.1 = 1      'just to see progress
delay_ms(500)
select case pre
case 0
PORTB = 1
case 1
PORTB = 2
case 2
PORTB = 4
case 3
PORTB =8
end select
 PORTE.1 = 0         'just to see progress
delay_ms(500)
goto zacetek
  
  
end.
 

Hi,
Try this:
Code:
program BCD887

dim pre as byte


sub procedure interrupt ' Interrupt routine
pre =  PORTD
TMR0 = 155              ' Timer0 (or counter) returns its initial value
T0IF_bit = 0 'Timer flag is cleared, interrupt is enabled on its own
end sub


main:
     ANSEL = 0
     ANSELH = 0
     OPTION_REG = 0x04       ' Prescaler (1:32) is assigned to Timer0
     TMR0 = 155              ' Timer0 counts from 155 to 255
     INTCON = 0xA0           ' Enable interrupt on TMR0 overflow
     TRISB = %00000000    'output = 0
     TRISD = %11111111    'input = 1
     TRISE.B0 = 0          'output = 0
     TRISE.B1 = 0          'output = 0
     PORTB = 0 'PORTB initially has some value that is cleared
     while true
           PORTE.B1 = 1      'just to see progress
           delay_ms(500)
           select case pre
                  case 0
                       PORTB = 1
                  case 1
                       PORTB = 2
                  case 2
                       PORTB = 4
                  case 3
                       PORTB =8
           end select
           PORTE.B1 = 0         'just to see progress
           delay_ms(500)
     wend


end.

16F887 has ADC inputs at PORTB. To use PORTB as digital I/O, you must disable ADC by:
Code:
ANSEL = 0
ANSELH = 0

Read more about it in ADC section.

Hope this helps.
Tahmid.

---------- Post added at 15:40 ---------- Previous post was at 15:35 ----------

In the ISR, only clear the flag, you don't need to set the interrupt again.
When you declare a port as output by setting the tris bits, it has an initial value, that should be cleared.

I showed these in the code.

Hope you understood.
Tahmid.
 
THX
When I will be back home I will test this.
Thank you really!
 

Thx
Sorry for late response, but I was just come home from business trip :(
It's working..I change a little structure bit but now is working.
I’m trying to build something light sound dependent fleshing light or bather like spectrum-analyzer but only 4 or 8 canal. Do you have any idea or code for that? I’m trying with FF algorithm but there is nothing to found in VB code that I will be able to understand easily. Maybe some other method or principle....suggest whatever!
 

Please...have someone some idea to create sound base light show? :)
 

I'm not sure what you mean, could be a little more specific. Is it something like a disco lighting system that changes colour according to sound input?
 

Yes correct 4 to 8 channel light show....this I would like to prefer, but each channel should be separate frequency channel.
thx
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top