View previous topic :: View next topic |
Author |
Message |
yie23
Joined: 09 Dec 2010 Posts: 11
|
eeprom write interrupt |
Posted: Thu Dec 09, 2010 1:48 pm |
|
|
I'm noob in writing code. Are this correct ?
Code: | #include <16f877a.h>
#use delay(clock=20000000)
#fuses hs,noprotect,nowdt,nolvp
#byte portb=6
enable_interrupts(int_rda);
enable_interrupts(global);
|
|
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Thu Dec 09, 2010 2:00 pm |
|
|
Correct to do what? If you want an interrupt when a write to the chip's internal EEPROM completes, you would want to use Code: | enable_interrupts(INT_EEPROM); |
|
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 2:12 pm |
|
|
If it correct to initializes interrupt ?
Can you correct my mistake in this code ?
Code: |
void main()
{
set_tris_b(0b00000000);
do
{
output_high(pin_B1);
delay_ms(2000);
output_low(pin_B1);
delay_ms(2000);
}while(1);
|
How to insert interrupt in that coding ? |
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Thu Dec 09, 2010 2:39 pm |
|
|
Again.. what are you trying to do? So far nothing you have posted involves writing to the internal EEPROM. The first piece of code you posted enabled the wrong interrupt (INT_RDA) but not INT_EEPROM. So, if you want to enable the EEPROM write interrupt you would put the following somewhere in your code -- usually in main(), before the do...while() loop:
Code: |
void main() {
set_tris_b(0b00000000);
enable_interrupts(INT_EEPROM);
enable_interrupts(global);
do {
output_high(pin_B1);
delay_ms(2000);
output_low(pin_B1);
delay_ms(2000);
}while(1);
}
|
You can then write the interrupt service routine to do whatever you want to do when an EEPROM write finishes.
I can't think of a situation where I would want to, though... |
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 2:49 pm |
|
|
erm , actually i have to make led toggle continuously at port RB1 , RB2 and RB3 and toggle buzzer on and off in sequence every 1 sec using eeprom write interrupt . somehow , could u help me ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 09, 2010 2:57 pm |
|
|
Please don't sign up under several names. It becomes apparent that
yie23 = fariq23 = chemtastic23.
It is not considered to be polite to the forum members to pretend
to be several different people. But you all have the same identical
question.
Keep one name only, and ask questions under that name. |
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 3:00 pm |
|
|
no no no , we are friend . 23 is our class name .
three of us are different person .
but we are in the same class
sorry if we had make u angry .
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Dec 09, 2010 4:01 pm |
|
|
Get it through _all_ your heads. Interrupts, each signal some specific _hardware_ event. They can't be made to do jobs other than the one they are designed to signal. The EEPROM write interrupt, signals that an EEPROM write has completed. It'll trigger typically 4mSec after an EEPROM write has been started. Nothing else will trigger it, it is _not_ suitable for measuring time, and it is rarely wanted or needed. If you want to handle times, then you need to be using a _timer_ (the name says it all...). |
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 4:06 pm |
|
|
But, my job is to make interrupt using an eeprom. The task had been given that way. So, I had to follow it. I'm surely not understand enough how eeprom write interrupt work. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Dec 09, 2010 4:32 pm |
|
|
OK, the best way to get information on this type of thing is to search. Use Google and use the CCS forum search.
To answer your question, enabling an interrupt to occur when a write to EEPROM is completed you have to create an interrupt routine to service the interrupt like this:
Code: |
#int_eeprom
void eeprom_interrupt_routine(void)
{
EEPROMWriteCompletedFlag=1;
//This flag being set indicates the write to EEPROM has been completed.
//When you see this set in the main routine you can then do what you need to do.
}
|
Then you would enable the interrupt as you had earlier
Code: |
enable_interrupts(INT_EEPROM);
enable_interrupts(global);
|
You and your friends need to study up on interrupts and how they work.
Asking your teacher is a real good way to get this information unless they don't know in which case you are all in trouble! _________________ Google and Forum Search are some of your best tools!!!! |
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 5:02 pm |
|
|
oh , then if i need to insert interrupt
the program should be like this ?
Code: |
#include <pic.h>
int i=0;
int j=0;
//---Function Definition-----
//--Interrupt Beep function--
interrupt beep(void) // Interrupt function definition
{
if (INTF) // If the external flag is 1, do .....
{
INTF=0; // Reset the external interrupt flag
for(i=0;i<300;i++) // A loop for creating a beep sound
{
RA4=0; // By setting LED RA4 high and low...
RC2=1; // the will blink
for(j=0;j<10;j++); // By setting the RC2 high and low ...
RA4=1; //freguently, a sound is generated
RC2=0;
for(j=0;j<10;j++);
}
}
}
//--Main Funtion --
void main(void)
{
TRISA=0; // Ser PORT A as an OUTPUT
TRISB=0; // Set PORT B as an OUTPUT
TRISC=0; // Set PORT C as an OUTPUT
PORTC=0; // Set the value of PORT C to 0
INTF=0; // Reset the external interrupt flag
INTE=1; // Enable external interrupts from RB0
GIE=1; // Global interrupt enable
while(1)
{
PORTB++;// Increase the PORT B value by 1.
for(i=0;i<30000;i++); // a simple delay
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 09, 2010 6:00 pm |
|
|
That code is for the Hi-Tech C compiler. It's not for CCS. The various
C compilers for PICs are not compatible. That code came from here:
http://www.microcontrollerboard.com/pic_interrupt.html
Taking Hi-Tech C code off the net and re-posting it on this forum is useless. |
|
|
yie23
Joined: 09 Dec 2010 Posts: 11
|
|
Posted: Thu Dec 09, 2010 6:27 pm |
|
|
oh , so can u suggest me a good website for this coding ? |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Dec 09, 2010 11:03 pm |
|
|
Start with the Microchip website and download AND read through the datasheet for the processor you are working with. Yes, I know it is a big document (the one for the 18F14k22 is 388 pages). Read through the sections in particular on interrupts and how they work. Grab a copy of the CCS compiler manual (if that is the C compiler you are using) and read the sections in there on interrupts and DataEEPROM etc. Do some searching on "Interrupt Service Routines" and how they work and what should be done in them AND what should NOT be done in them. Until you really understand what it is you are trying to do, you will not get anywhere. Before you write code, you need to have a clear picture of just what the requirements are and what you are trying to accomplish. Once you have that understanding, then the code part should be easy.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|