Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mega32.h>
- #include <stdio.h>
- #define MAX 10
- #define MAXANGLE 1999
- #define MINANGLE 999
- #define MOTOR_PLUS 0x01
- #define MOTOR_MINUS 0x02
- #include <delay.h>
- unsigned char data;
- void init()
- {
- PORTA=0x01;
- DDRA=0x00;
- PORTB=0x00;
- DDRB=0x40;
- PORTC=0x00;
- DDRC=0x00;
- PORTD=0x00;
- DDRD=0b10100010;
- TCCR1A=0b10000010;
- TCCR1B=0b00011001;
- ICR1H=0x4E;
- ICR1L=0x1F;
- OCR1A = 1499;
- TIMSK=0b00000000;
- UCSRA=0x02;
- UCSRB=0xD8;
- UCSRC=0x86;
- UBRRH=0x00;
- UBRRL=0x0C;
- ACSR=0x80;
- SFIOR=0x00;
- SPCR=0b11001000;
- SPSR=0x00;
- }
- interrupt [SPI_STC] void spi_isr(void)
- {
- data=SPDR;
- }
- void main(void)
- {
- bit state = 0;
- unsigned int Press_Conf = 0;
- char cmd[] = "horzental:122";
- init();
- // Clear the SPI interrupt flag
- #asm
- in r30,spsr
- in r30,spdr
- #endasm
- #asm("sei")
- while (1)
- {
- // Place your code here
- if(data == MOTOR_PLUS)
- {
- if(OCR1A <= MAXANGLE)
- {
- OCR1A++;
- PORTD ^= 1 << PIND7;
- data = 0x00;
- }
- }
- else if(data == MOTOR_MINUS)
- {
- if(OCR1A >= MINANGLE)
- {
- OCR1A--;
- PORTD ^= 1 << PIND7;
- data = 0x00;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment