下载此文档

舵机程序.doc


文档分类:行业资料 | 页数:约3页 举报非法文档有奖
1/3
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/3 下载此文档
文档列表 文档介绍
舵机程序
下面的演示程序中,舵机的输出轴在一定的角度范围内做周期性摆动。
舵机型号为Tower Pro Micro Servo 99 SG90,单片机型号为Atmega16。
对照右边的实物图,舵机的引出线依次为: GND(褐色),VCC(红色),CONTROL(橙黄)。VCC,GND为舵机的电源线(+5V),CONTROL(PWM波形)为舵机控制信号的输入线。

//ICC-AVR application builder : 2010-11-6 19:14:54
// Target : M16
// Crystal:
#include <>
#include <>
#define uchar unsigned char
#define uint unsigned int
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x10;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER1 initialize - prescale:8
// WGM: 15) PWM fast, TOP=OCRnA
// desired value: 50Hz
// actual value: (%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x00; //setup
TCNT1L = 0x00;
OCR1AH = 0x09;
OCR1AL = 0xC3;
OCR1BH = 0x09;
OCR1BL = 0xC3;

TCCR1A = 0x03;
TCCR1B = 0x1A; //start Timer
}
#pragma interrupt_handler pa_isr:7
void pa_isr(void)
{
//compare occured TCNT1=OCR1A
TCNT1H = 0x00;
TCNT1L = 0x00;
PORTB|=(1<<PB4);
}
#pragma interrupt_handler pb_isr:8
void pb_isr(void)
{
//compare occured TCNT1=OCR1B
PORTB&=~(1<<PB4);
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
p

舵机程序 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数3
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小528 KB
  • 时间2018-02-27