i was wondering if these additions to SOR_utils would work. I'm confused as to weather or not the H-bridge(L293D) has its own ports and if so how to call on them. so I'm posting the code i think will work to see if this can be explained further.
/****************************************************************************
*
* Copyright (c) 2007 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
* (please link back if you use this code!)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* SoR Utilities v1, March 10th, 2007
*
****************************************************************************/
//AVR includes
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support
//AVRlib includes
#include "global.h" // include global settings
//#include "buffer.h" // include buffer function library
//#include "uart.h" // include uart function library
//#include "rprintf.h" // include printf function library
//#include "timer.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library
//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )
#define L293D_A P2_0
#define L293D_B P2_1
#define L293D_E P2_2
//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00; //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF; //configure all D ports for output
DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')
}
//***************************************
//************DELAY FUNCTIONS************
//wait for X amount of cycles (23 cycles is about .992 milliseconds)
//to calculate: 23/.992*(time in milliseconds) = number of cycles
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
void DC_Forward(signed long int speed){
PORT_ON(PORTD, 1);
PORT_ON(PORTD, 0);
L293D_A = 1;
L293D_B = 0;
L293D_E = 1;
delay_cycles(speed);
PORT_OFF(PORTD, 1);
PORT_OFF(PORTD, 0);
}
void DC_Backward(signed long int speed){
PORT_ON(PORTD, 1);
PORT_ON(PORTD, 0);
L293D_A = 0;
L293D_B = 1;
L293D_E = 1;
delay_cycles(speed);
PORT_OFF(PORTD, 1);
PORT_OFF(PORTD, 0);
}
void DC_breaks(){
L293D_A = 0;
L293D_B = 0;
L293D_E = 0;
PORT_OFF(PORTD, 1);
PORT_OFF(PORTD, 0);
}
//***************************************
Ok I'm editing my post because i now understand that there are pins but i am still not sure how to call on them my best guess is in my code L293D_A = 0 shuts off some port i think but i don't know witch port or if it even dose shut off a port. so some clarity on that would be grate.