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.

Question about Hz and programming

Status
Not open for further replies.
So I finally found a place I can mooch some internet connection till tomorrow when they get our internet set up. So I got out of class today and worked on some code, it's really simple but I'm still not sure I've got all the registers set up right but I figured I'd post it and see if it's right or not. All the code is supposed to do is turn a servo to 90 degrees. If I had the code right I was going to edit it to do more stuff but like I said I'm not sure I got the registers set up right. I'm hopefully going to get to order some servos sometime in the next few weeks and then I'll get to actually test some of my code and see if it works. I appreciate all the help guys.

Code:
int servopos;
Int main(){
OSCCON = 0b00001010;
INTCON = 0b11000000;
PIE = 0b00000110;
T1CON = 0b10010001;
CCP1CON = 0b00001011;
TRISA = 0b00000000;
PORTA = 0b00000000;
servopos = 1500;
CCPR1 = servopos;
while (1){
while (!PIR1.CCP1IF){
PORTA.F0 = 0;
CCPR1 = 20000 - servopos;
PIR1.CCP1IF = 0;
while (!PIR1.CCP1IF){
PORTA.F0 = 1;
CCPR1 = servopos;
PIR1.CCP1IF = 0;
}}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top