Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mega32a.h>
- #include <delay.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <spi.h>
- #define MAX 10
- #define MAXANGLE 1999
- #define MINANGLE 999
- #define MOTOR_PLUS 0x01
- #define MOTOR_MINUS 0x02
- #define REMOTE_MOTOR 0x03
- unsigned int dump_mode1 = 1; //this dump variable is to keep synchronization with master
- unsigned int dump_mode2 = 1; //this dump variable is to keep synchronization with master
- unsigned int dump_mode3 = 1; //this dump variable is to keep synchronization with master
- unsigned int dump_mode4 = 1; //this dump variable is to keep synchronization with master
- // SPI interrupt service routine
- interrupt [SPI_STC] void spi_isr(void)
- {
- unsigned char data;
- data = SPDR;
- if(data == MOTOR_PLUS) // condition used for Auto/Manual mode
- {
- if(OCR1A <= MAXANGLE)
- {
- OCR1A++;
- PORTD ^= 1 << PIND7;
- }
- }
- else if(data == MOTOR_MINUS) // condition used for Auto/Manual mode
- {
- if(OCR1A >= MINANGLE)
- {
- OCR1A--;
- PORTD ^= 1 << PIND7;
- }
- }
- else
- {
- OCR1A = data * 10; //returning the value back to the PWM range values then assign it to OCR1A
- PORTD ^= 1 << PIND7;
- }
- }
- // Declare your global variables here
- void init()
- {
- PORTA=0x00;
- DDRA=0x00;
- PORTB=0x00;
- DDRB=0x40;
- PORTC=0x00;
- DDRC=0x00;
- PORTD=0x00;
- DDRD=0xA0;
- TCCR1A=0b10000010;
- TCCR1B=0b00011001;
- ICR1H=0x4E;
- ICR1L=0x1F;
- OCR1A = 1499;
- TIMSK=0x00;
- ACSR=0x80;
- SFIOR=0x00;
- SPCR=0xC0;
- SPSR=0x00;
- }
- void main(void)
- {
- // Clear the SPI interrupt flag
- #asm
- in r30,spsr
- in r30,spdr
- #endasm
- // Global enable interrupts
- #asm("sei")
- init();
- while (1)
- {
- // Place your code here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment