CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Settings of timer1 interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
isoment01



Joined: 20 May 2017
Posts: 7
Location: turkey

View user's profile Send private message

Settings of timer1 interrupt
PostPosted: Fri Jun 30, 2017 6:42 am     Reply with quote

Hello everyone again. I have a problem with Timer1 interrupts in my code. I want to generate pulses that drive my stepper motor. My motor is gonna work 8 sec (3200 pulses) and stop 4 sec continuously by using Timer1 but i couldn't handle this. Can you help me to set this Timer1 ?
Code:
#device PIC16F877A

#include <16f877a.h>
#fuses xt,nowdt,noprotect, nobrownout, nolvp, noput, nowrt, nocpd
#use delay (clock=4000000)
#use fast_io(b)
#use rs232 (baud=9600,xmit=pin_C6, rcv=pin_C7, parity=N, stop=1, Bits=8)
unsigned int16 counter = 0, interrupt=0; //
char operation;

//#priority rda, timer1
void right_direction_commands()
{
output_high(pin_b3);// motor aktif,motor enable pin
delay_ms(100);
output_high(pin_b1);// motor yönü belirlendi, motor direction pin
sayac=3200;
printf("\r\n right start\r\n");
}

void left_direction_commands()
{
 output_high(pin_b3);
 delay_ms(100);
 output_low(pin_b1);
 sayac=3200;

 printf("left start \n\r");
}

void stop_commands()
{
 output_low(pin_b3);
 sayac=0;
 printf("motor stop \n\r");
}
 
#int_rda
void serihaberlesme_kesmesi ()
{
operation=getch();/
 putc(ioperation);
output_toggle(pin_b0);

 if(operation=='r')
 {
  right_direction_commands();
 }
 
 if(operation=='l')
 {
  left_direction_commands();
 }

 if(operation=='s')
 {
  stop_commands()
 }

}
 

#int_timer1
void timer1_interrupts()
{
set_timer1(64923);
interrupt++;
output_high(pin_b2);
delay_us(20);
output_low(pin_b2);
if(interrupt==counter)
 {
  interrupt=0;
 }
}

void main()
{
delay_ms(300);
setup_psp(PSP_DISABLED);
setup_timer_2 (T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
set_tris_b(0x00);
output_b(0x00);

setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);  //262 ms overflow      //65,5 ms overflow
set_timer1(64923);

enable_interrupts(GLOBAL);
enable_interrupts(INT_rda);
enable_interrupts(INT_timer1);

printf("\n\r System initializing....\n\r");
printf("\n\r bir islem seciniz...\n\r");

while(TRUE)
 {

 }

}

_________________
hello everyone !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group