12.07.2015 Views

Programming Manual Elektor Proton Robot - ELEKTOR.se

Programming Manual Elektor Proton Robot - ELEKTOR.se

Programming Manual Elektor Proton Robot - ELEKTOR.se

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The MD25 motor driver moduleThis program displays the battery voltage – measured by the MD25 module.If you press the red button, the robot will drive backward – the encoder decrements until it reaches 165and the motor stops (255- 90 = 165)If you press the black button, the robot will drive forward until the encoder reaches 90 and at that timethe motors stopsPIC16F887Demoprogram Flowcode PIC V4PROTDEM_FCPIC_MD25.fcfDemoprogram Hitech C lite for PIC#include #include "PIC_PROTON_LIB.h"#define _XTAL_FREQ 19660800__CONFIG(0x2ff2); // <strong>se</strong>t HS Xtal etc__CONFIG(0x3fff);void main(){// init AD & Option regANSEL = 0;ANSELH = 0;OPTION = 0xC0;// end of init__delay_ms(250);__delay_ms(250); //wait for stable power supplyI2C_INIT(); // initialize I2C - LCD03 is a I2C LCDvolatile unsigned char ENC=0, VOLT=0;I2C_SEND_MESSAGE(0xB0,16,50); // Disable 2 <strong>se</strong>ctimeout in command regTRISB |=0b00110000; //B4-B5 input - SWITCHESwhile (1){VOLT = I2C_RECEIVE_MESSAGE(0xB0,10);LCD03_CLEAR_SCREEN();LCD03_SET_CURSOR(1);char String[20] = "BATT_VOLT: ";LCD_WRITE_STRING(String);LCD03_WRITE_BYTE(VOLT);if (PORTB & 0b00010000) //red switch{I2C_SEND_MESSAGE(0xB0,16,32); //clear allencoder registersI2C_SEND_MESSAGE(0xB0,0,121);I2C_SEND_MESSAGE(0xB0,1,121);ENC = 255;ATMEGA32Demoprogram Flowcode AVR V4PROTDEM_FCAVR_MD25.fcf_avrDemoprogram WinAVR C for AVR#include #define F_CPU 19660800UL#include #include "AVR_PROTON_LIB.h"#include "AVR_PROTON_LIB.c"int main ( void ){_delay_ms(250);_delay_ms(250); //wait for stable power supplyI2C_INIT(); // initialize I2C - LCD03 is a I2C LCDvolatile unsigned char ENC=0, VOLT=0;I2C_SEND_MESSAGE(0xB0,16,50); // Disable 2 <strong>se</strong>ctimeout in command regwhile (1){VOLT = I2C_RECEIVE_MESSAGE(0xB0,10);LCD03_CLEAR_SCREEN();LCD03_SET_CURSOR(1);LCD03_WRITE_STRING("BATT_VOLT: ");LCD03_WRITE_BYTE(VOLT);if (PIND & 0b00000100) //red switch{I2C_SEND_MESSAGE(0xB0,16,32); //clear allencoder registersI2C_SEND_MESSAGE(0xB0,0,121);I2C_SEND_MESSAGE(0xB0,1,121);ENC = 255;_delay_ms(30); // When read to fast - value is still0while (ENC > 165) // wheels turn backwards -encoder counts back{ENC = I2C_RECEIVE_MESSAGE(0xB0,2); //Bart Huyskens <strong>Manual</strong> <strong>Elektor</strong> <strong>Proton</strong> V1.0 3 April 2011 71

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!