
Çok ilginç bir robot projesi pencelerelerdeki sineklikleri temizleme içintasarlanmış temizlikci robot sistemin beyni atmel at90ls8535 mikro denetleyicisi kaynak c yazılımı verilmiş.
Robot projesinin uygulayamasanızda devre bölümleri kaynak yazılım işinize yarayabilir özellikle motor sürücü bölümü h-bridge köprü bağlantılı mosfetli sürücü katı bulunuyor

mrfisc.c yazılımı
/*********************************************
Project : MrFisc
Version : 1.0
Date : 9/12/2003
Author : Andrew Oudyn
Comments:
Firmware for the Mr Fisc
Micro Robotic Fly & Insect Screen Cleaner
Chip type : AT90LS8535
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*********************************************/
// include files for this project
#include <90S8535.h> //contains register information for the processor
#include <stdio.h> // Standard Input/Output functions
#include <delay.h> //Delay functions
#include <math.h> //Maths library
#include <stdlib.h> //for ftoa
#include "mrfisc.h"
//Set and read individual bits Macro
#define setBit(port, bitP, value) if (value == 1) { port = port | (1<<(bitP)); } else { port = port & ~(1<<(bitP)); }
#define getBit(port,bitP) ((port & (1<<(bitP)))>>(bitP))
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input;
// Start the AD conversion
ADCSR|=0x40;
// Wait for the AD conversion to complete
while ((ADCSR & 0x10) == 0);
ADCSR|=0x10;
return ADCW;
}
void check_status(void);
void motor(unsigned char action);
void wait(void);
void initialise(void);
void correct(void);
// Global Variables
float angle = 0; //the angle of Mr. FISC
float vBat = 0; // Battery Status in Volts
signed int heading = 0; //the nearest integer value for the heading in degrees
unsigned char direction = HEAD_RIGHT; //always start at the top left so always go right
unsigned char whichway;
void main(void)
{
unsigned char start = 1; //To signify program initialisation
initialise();
DDRC = SetPortC; //0011 0000 set the port C to external input.
whichway = STOPPED;
wait();
while (1)
{
if(PINC.RIGHT_SENSOR == 1)
{
heading = 0;
start = 0;
}
else if(PINC.LEFT_SENSOR == 1)
{
heading = 0;
}
else if(PINC.FRONT_SENSOR == 1)
{
motor(STOP);
direction = HEAD_LEFT;
if(start == 0)
{
motor(STOP);
wait();
start = 1;
}
heading = TRAJECTORY; // heading in degrees
}
else if(PINC.BACK_SENSOR == 1)
{
motor(STOP);
direction = HEAD_RIGHT;
if(start == 0)
{
motor(STOP);
wait();
start = 1;
}
heading = -TRAJECTORY; // heading in degrees
}
correct();
}
}
/* check_status() is used to read all of the ADC values going into the micro.
These include the battery voltage, the X and Y tilt values from the
accelerometer. Port A is also used as a digital IO port and aswell
as taking the anologue tilt readings, a digital version can also be
obtained by pooling the two digital input pins, 4 and 5 and using a
timer counter. Port A also control the Serial IC and the Charge pump.
*/
void check_status()
{
float xTilt = 0; // Value of tilt in X direction
float yTilt = 0; // Value of tilt in Y direction
float xTiltDigi = 0;
int countT1 = 0; // time in counts for high pulse
int countT2 = 0; // time in counts for low pulse
char buffer[] = {0,0,0,0,0,0,0,0,0,0}; // buffer to hold number sent to computer
//accelerometer sensativity (60mV x Vcc)/g = (198mV / g)
// "zero g" will be at Vcc/2 = 1.65
// use full 10 bit ADC total range of 3.3V / 2^10 = 1024
// Voltage step = 3.22mV / bit
// Battery Status
//tiltValue = (float)(read_adc(V_BAT));
vBat = (float)(read_adc(V_BAT)*VOLTS_PER_BIT);
/* ******* ANALOGUE TILT READINGS ******* */
//tiltValue = read_adc(X_TILT); //read the X tilt value
xTilt = (float)read_adc(X_TILT)*VOLTS_PER_BIT;
//tiltValue = read_adc(Y_TILT); //read the Y tilt value
yTilt = (float)read_adc(Y_TILT)*VOLTS_PER_BIT;
/* ******* DIGITAL TILT READINGS ******* */
DDRA = SetPortA; // 1100 0000
// Y tilt readings
// The actual time taken is irrelevent, it's the duty cycle that is important
// so the delay to keep track of actual time is not required, so long as the
// loops are the same.
while(PINA.X_TILT_DIGI == 1){}
while(PINA.X_TILT_DIGI == 0){} //wait for clock to pulse
while(PINA.X_TILT_DIGI == 1){ countT1++; }
while(PINA.X_TILT_DIGI == 0){ countT2++; }
xTiltDigi = ((float)countT1/(countT2 + countT1) - ZERO_G_CYCLE)/CYCLE_2_G;
/* ******* CALCULATING AND SENDING ANGLE ******* */
setBit(PORTA, RS232_ON, 1); //turns on the serial IC
delay_ms(1);
angle = asin(xTiltDigi)*RADS_2_DEGS; //convert to degrees
ftoa(angle, 4, buffer);
printf("Mr. FISC's DIGITAL Y tilt readings show: %s r n", buffer);
printf("Heading: %d r n", heading);
if(whichway == FORWARD)
printf("Mr. FISC is going FORWARD r n");
else if(whichway == FORWARDLEFT)
printf("Mr. FISC is going FORWARD and LEFT r n");
else if(whichway == FORWARDRIGHT)
printf("Mr. FISC is going FORWARD and RIGHT r n");
else if(whichway == BACKWARDS)
printf("Mr. FISC is going BACKWARDS r n");
else if(whichway == BACKLEFT)
printf("Mr. FISC is going BACK and LEFT r n");
else if(whichway == BACKRIGHT)
printf("Mr. FISC is going BACK and RIGHT r n");
else if(whichway == STOPPED)
printf("Mr. FISC ain't goin' NOWHERE r n");
//ftoa(vBat, 3, buffer);
//printf("The battery Voltage is: %s r n", buffer);
delay_ms(10);
setBit(PORTA, RS232_ON, 0); //turns off the serial IC
}
void correct(void)
{
check_status();
if(direction == HEAD_RIGHT)
{
if(heading == 0)
{
if(angle >= STRAIGHTLINE)
{ motor(RIGHT_FWD); whichway = FORWARDRIGHT; }
else if(angle <= (0 - STRAIGHTLINE))
{ motor(LEFT_FWD); whichway = FORWARDLEFT;}
else
{ motor(FWD); whichway = FORWARD; }
}
else
{
if(angle >= (heading + STRAIGHTLINE))
{ motor(RIGHT_FWD); whichway = FORWARDRIGHT; }
else if(angle <= (heading - STRAIGHTLINE))
{ motor(LEFT_FWD); whichway = FORWARDLEFT; }
else
{ motor(FWD); whichway = FORWARD; }
}
}
else if(direction == HEAD_LEFT)
{
if(heading == 0)
{
if(angle <= (0 - STRAIGHTLINE))
{ motor(LEFT_REV); whichway = BACKLEFT; }
else if(angle >= (STRAIGHTLINE))
{ motor(RIGHT_REV); whichway = BACKRIGHT; }
else
{motor(REV); whichway = BACKWARDS;}
}
else
{
if(angle >= (heading + STRAIGHTLINE))
{ motor(RIGHT_REV); whichway = BACKRIGHT; }
else if(angle <= (heading - STRAIGHTLINE))
{ motor(LEFT_REV); whichway = BACKLEFT; }
else
{ motor(REV); whichway = BACKWARDS; }
}
}
}
void motor(unsigned char action)
{
//flag to determine if Mr FISC is already moving to prevent lots of stop starts
if(action == FWD){ PORTB = MOTOR_FWD; }
else if(action == REV){ PORTB = MOTOR_REV; }
else if(action == LEFT_FWD){ PORTB = MOTOR_LEFT_FWD; }
else if(action == RIGHT_FWD){ PORTB = MOTOR_RIGHT_FWD; }
else if(action == LEFT_REV){ PORTB = MOTOR_LEFT_REV; }
else if(action == RIGHT_REV){ PORTB = MOTOR_RIGHT_REV; }
else if(action == STOP){ PORTB = MOTOR_STOP; }
}
void wait(void)
{
while(!((PINC.RIGHT_SENSOR == 1)&&(PINC.LEFT_SENSOR == 1)))
{
PORTD = ALL_RED; //1010 1000
delay_ms(175);
PORTD = ALL_GREEN; //0101 0100
delay_ms(175);
}
PORTD = ALL_OFF;
delay_ms(500);
PORTD = POWERON; //1100 1100 lights on...
}
void initialise(void)
{
// UART initialization Communication Parameters: 8 Data, 1 Stop, No Parity
UCR=0x18; // UART Receiver: On UART Transmitter: On UART Baud rate: 9600
UBRR=0x19;
ACSR=0x80; // Analog Comparator initialization
ADCSR=0x85; // ADC Clock frequency: 125.000 kHz
// Port A initialization
PORTA = StartPortA; //1000 0000
DDRA = SetPortA; //O,O,I,I, I,I,I,I
// Port B initialization
PORTB = StartPortB; //0000 0000
DDRB = SetPortB; //I,I,I,I, O,O,O,O
// Port C initialization
PORTC = StartPortC; //0000 0000
DDRC = SetPortC; //I,I,O,O, I,I,I,I
// Port D initialization
PORTD = StartPortD; //1111 1100
DDRD = SetPortD; //O,O,O,O, O,O,X,X
}
Kaynak: innovexpo.itee.uq.edu.au/2003/exhibits/s363161/
sineklik-temizleme-robotu-atmel-at90ls8535-bocek-robot-dw-link ZIP Dosyası Şifre-Pass: 320volt.com