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.

interrupt based program for pic16f877

Status
Not open for further replies.

bluemonday

Newbie level 6
Joined
May 4, 2007
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,395
pic16f877 timer interrupt

hi.. i used this code to program my pic..
unsigned int adc_value;

void main() {
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // Pins RB7, RB6 are outputs

Usart_Init(115200);

do {
adc_value = Adc_Read(2); // Get results of AD conversion
Usart_Write(adc_value);
Delay_us(200);
} while(1);
}

i cant get an accurate sampling.. can anyone help me with this.. i want to use an interruput based timer for this but im dont know how.. plz help me.. anybody who knows.. plz let me have ur code..
 

pic16f877 interrupt

hi,

i think u r using mikroc compiler


void interrupt()
{
if(PIR1.TMR1IF)
{
//put ur code here
PIR1.TMR1IF = 0; // clear TMR1IF
}

}
void init_timer()
{
TMR1L = 0;
TMR1H = 0;
T1CON = 0x31;
PIR1.TMR1IF = 0; // clear TMR1IF
PIE1 = 1; // enable interrupts
INTCON = 0xC0;
}

u can initialize timer using the function init_timer()
when the timer overflow occurs, the function interrupt() will automatically called
 

pic16f877a interrupt

also you can use the "special event" of the CCP module... you could read it in the datasheet (sorry i don`t remember if the 877 and the 877A have this module...) you should change the ccpr2 values for your own requirements... (I just modified and old program to post here....)(it worked vary well for me...)

void interrupt (void)
{
if (PIR2.CCP2IF)
{
PIR2.CCP2IF=0;
Usart_write(ADRESH);
}
}

void main(void)

{
TRISA=0xEF; // or something more...
TRISB=0;
TRISD=0;
PORTB=0;
PORTD=0;
Usart_Init(115200);
ADCON0 =0b01000001; // ADC setting
ADCON1 =0x04;
T1CON=0; //
CCPR2H=0x04;
CCPR2L=0xE2; // Fs = 800Hz = 1/1250us
TMR1H=0; //
TMR1L=0; //
CCP2CON=0x0B;
PIR2.CCP2IF=0;
PIE2.CCP2IE=1;
INTCON.PEIE=1;
INTCON.GIE =1;
T1CON.TMR1ON=1;
ADCON0.GO=1;

while (1)
{
//put something more here.....
}
}
 

timer interrupt in pic 16f877

Check the datasheet and pay attention the term 'Tad'
 

pir1 tmr1if

i haver read the data sheet and these steps should be done on an A/D conversion:

1. configure the A/D module:
2. configure A/D interrupt:

•clear ADIF bit
•set ADIE bit
•set PEIE bit
•set GIE bit
3. wait for acquisition time
4. start cpnversion

•set GO/DONE bit (ADCON0)

5. wait for A/D conversion to complete, by either:

•polling for the GO/DONE bit to be cleared (w/ interrupts enabled) OR
•waiting for A/D interrupt

i know how to do step 1.. but im not sure what to do for the next steps.. can you please explain to me if you have the time.. your help will we highly appreciated.. thnx a lot..

Added after 7 minutes:

and also.. i want to transmit the ADRESL.. how will i do that??

Added after 10 minutes:

and also.. CCPR2h = 0x04
CCPR2L = 0xE2

can you please explain it more why you put this values?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top