Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
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}
while (1){ //store sensor data sensor_right=a2dConvert8bit(PC4); sensor_left=a2dConvert8bit(PC5); //detects more light on left side of robot if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold) { //go left PORT_ON(PORTD, PD2); PORT_OFF(PORTD, PD3); //servo_left(44); //servo_right(44); } //detects more light on right side of robot else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold) { //go right PORT_OFF(PORTD, PD2); PORT_ON(PORTD, PD3); //servo_left(25); //servo_right(25); } //light is about equal on both sides else if (sensor_left == 0 && sensor_right == 0) { //go straight PORT_OFF(PORTD, PD2); PORT_OFF(PORTD, PD3); //servo_left(25); //servo_right(44); } else { PORT_ON(PORTD, PD2); PORT_ON(PORTD, PD3); } delay_cycles(10000); } return 0;}
To configure ports, you must first decide which ports you want as analog inputs, and which ports you want as digital outputs.Just let me know and Ill write some quick config code for you.This post might help you some:http://www.societyofrobots.com/robotforum/index.php?topic=1372.0
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
What is actually happening in this function, what are DDRC, PORTC, DDRD? I have not got problems with the c-code, but the microcontroller stuff is new to me.
Also I have measured the voltage on the PCx pins, and some of them (PD2, PD3, PD5) seem to be at ~3V, whereas the others, (PD0, PD1, PD4, PD6, PD7) are 0V. Is that normal?
DDRD = 0xFF; //configure all D ports for outputPORTD = 0x00; //set PD[0-7] to 0V
Further more, are the a2d.h etc. in the $50 tutorial hand-written or could you find similar functionality in the AVR library?
Finally, in the makefile, what is the highest I can savely set F_CPU to for the ATMega32, I have currently set it at 3686400 but I might as well make the best use of the chip if it can go higher without an external oscillator.