210 likes | 341 Vues
This project involves implementing advanced control and programming techniques in a robotics laboratory setting at the Technion - Israel Institute of Technology. It focuses on using a PIC18F4431 microcontroller to manage various components including distance sensors, servo motors, and communication interfaces like RS232 and IrDA. The system includes detailed pin configurations, initialization routines, and interrupt service routines to effectively control motors, read sensor data, and communicate with external devices, demonstrating innovative applications of robotics and programming aids.
E N D
Robotrafficsoftware and programming aids Robotics Laboratory Faculty of Mechanical Engineering Technion Israel Institute of Technology
Strip sensor Distance Sensor Servo Motor PICKit 2 Reset RS232 5Vdc out Run/Stop Select rs232 or IrDA Select rs232 Encoder IrDA BUS jumpers Fuse 5A DC Motor Power input Car main board
Strip sensor (J11) 1 – pin Vdd 2 – pin Gnd 3 – pin Left 4 – pin BL 5 – pin BR 6 – pin Right 7 – pin Stop Distance Sensor (J12) 1 – pin Vdd 2 – pin Gnd 3 - pin Left 4 – pin Right Servo Motor (J14) 1 –pin Vm 2 – pin Input 3 – pin Gnd PICKit 2 (J3) 1 - pin Vpp 2 – pin Vdd 3 – pin Gnd 4 – pin PGD 5 - pin PGC Reset (J6) 1 – pin Reset 2 - Gnd RS232 (J1) 1 – pin RX 2 - pin Gnd 3 – pin TX 5Vdc out (J16) 1 – pin +5Vdc 2 - Gnd Run/Stop (J15) Open RC2->High Close RC2 -> Low 1-2 close RS232 2-3 close IrDA Encoder (J13) 1 – pin Vdd 2 – pin Gnd 3 – pin QEA 4 – pin QEB 5 – pin Index IrDA (J9) 1 –pin Vdd 2 – pin Gnd 3 – pin RXIr 4 – pin TXIr BUS jumpers Fuse 5A DC Motor (J10) 1 – pin (+)Motor 2 – pin (-)Motor Power input (J2) 1 – pin (+) Battery 2 – pin (-) Battery Car main board
PIC18F4431 PORTA TRISA = 0x00; TRISA0 = 0; PORTA = 0xFA; RA0 = 1; TRISA = 0xFF; TRISA0 = 1; char a = PORTA;
Exercise_1 Port setup #include<htc.h> char a = 0x55; void main(void) { TRISA = 0xf0; // b11111111 all bits, are input TRISA6 = 0; // bit RA6 set to output PORTA = a; }
#include<htc.h> char a; void initialization (void); void interrupt ISR(void); /*==============================================================*/ void initialization (void) { /* Interrupt init */ IPEN = 1; /* Interrupt Priority Enable bit, 1 = Enable priority levels on interrupts */ /* 0 = Disable priority levels on interrupts */ GIEH = 1; /* Enables all high priority interrupts */ GIEL = 1; /* Enables all low priority peripheral interrupts */ /* init TMR0 */ T0CON = 0x46; /* 16-bit 1:2 prescale value */ TMR0L = 0x80; /* prescaler for the Timer0 module */ TMR0H = 0x00; /* prescaler for the Timer0 module */ TMR0IP = 1; /* TMR0 Overflow Interrupt Priority bit, High priority */ TMR0IE = 1; /* Enables the TMR0 overflow interrupt */ TMR0IF = 0; /* TMR0 Overflow Interrupt Flag bit */ /* I/O ports */ TRISA = 0xff; /* Port A data direction */ TRISB = 0x00; /* Port B data direction */ } /*==============================================================*/ void interrupt ISR(void) { if((TMR0IF)&&(TMR0IE)) { PORTB = a; a++; TMR0L = 0x80; /* prescaler for the Timer0 module */ TMR0H = 0x00; /* prescaler for the Timer0 module */ TMR0IF = 0; /* TMR0 Overflow Interrupt Flag bit */ } } /*==============================================================*/ void main (void) { initialization (); TMR0ON = 1; /* Timer0 On/Off Control bit, 1 = Enables Timer0 */ while(1) { } }
ENHANCED UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (EUSART)