|
原创M48产生16路PPM信号控制16路舵机程序- //ICC-AVR application builder : 2013/9/15 7:09:24
- // Target : m48
- // Crystal: 8.0000Mhz
- #include <iom48v.h>
- #include <macros.h>
- void port_init(void)
- {
- PORTB = 0x00;
- DDRB = 0xFF;
- PORTC = 0x7F; //m103 output only
- DDRC = 0x00;
- PORTD = 0x00;
- DDRD = 0xFF;
- }
- //TIMER1 initialize - prescale:1
- // WGM: 14) fast PWM, TOP=ICRn
- // desired value: 2.5mSec
- // actual value: 2.500mSec (0.0%)
- void timer1_init(void)
- {
- TCCR1B = 0x00; //stop
- TCNT1 = 2500*8; //setup
- OCR1A = 2500*8;
- OCR1B = 2500*8;
- ICR1 = 2500*8;
- TCCR1A = 0x02;
- TCCR1B = 0x19; //start Timer
- }
- unsigned char n = 7;
- unsigned int htla[8]={1100*8,1200*8,1300*8,1400*8,1500*8,1600*8,1700*8,1800*8};
- unsigned int htlb[8]={1800*8,1700*8,1600*8,1500*8,1400*8,1300*8,1200*8,1100*8};
- #pragma interrupt_handler timer1_compa_isr:iv_TIM1_COMPA
- void timer1_compa_isr(void)
- {
- //compare occured TCNT1=OCR1A
- PORTB = 0;
- }
- #pragma interrupt_handler timer1_compb_isr:iv_TIM1_COMPB
- void timer1_compb_isr(void)
- {
- //compare occured TCNT1=OCR1B
- PORTD = 0;
- }
- #pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
- void timer1_ovf_isr(void)
- {
- //TIMER1 has overflowed
- PORTB = PORTD = BIT(n);
- n = n ? n-1 : 7;
- OCR1A = htla[n];
- OCR1B = htlb[n];
- }
- //call this routine to initialize all peripherals
- void init_devices(void)
- {
- //stop errant interrupts until set up
- CLI(); //disable all interrupts
- port_init();
- timer1_init();
- MCUCR = 0x00;
- EICRA = 0x00; //extended ext ints
- EIMSK = 0x00;
-
- TIMSK0 = 0x00; //timer 0 interrupt sources
- TIMSK1 = 0x07; //timer 1 interrupt sources
- TIMSK2 = 0x00; //timer 2 interrupt sources
-
- PCMSK0 = 0x00; //pin change mask 0
- PCMSK1 = 0x00; //pin change mask 1
- PCMSK2 = 0x00; //pin change mask 2
- PCICR = 0x00; //pin change enable
- PRR = 0xE7; //power controller
- SEI(); //re-enable interrupts
- //all peripherals are now initialized
- }
- //
- void main(void)
- {
- init_devices();
- //insert your functional code here...
- }
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|