Para mandarle unos comando al pic desde python:
import serial
RS232 = serial.Serial('/dev/ttyUSB0', 1200, timeout=1)
print RS232.portstr
RS232.write(raw_input(':'))
try:
dato=ord(RS232.read())
print dato
dato=ord(RS232.read())
print dato
except:
print "No se recibio ningun dato"
RS232.close()
Programa en C para el pic, utiliza interrupciones para recibir los datos n_n.
#include <pic16f873a.h>
typedef unsigned int word;
word at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _LVP_OFF &_DEBUG_OFF & _CPD_OFF &_PWRTE_ON &_BODEN_ON;
unsigned char Serial_RX(void);
void Serial_TX(unsigned char);
void isr() interrupt 0 {
unsigned char aux;
if (RCIF==1){
switch(RCREG){
case 'A':RB0=1;break;
case 'B':RB0=0;break;
}
}
Serial_TX('K');
RCIF=0;
}
void main() {
TRISB=0x0;
TRISC=0b10000000;
TXSTA=0b00100000;
SPBRG=255;
PIE1=0b00100000;
RCSTA=0b10010000;
INTCON=0b11000000;
PORTB=0x0;
while(1);
}
unsigned char Serial_RX(){
while(RCIF==0);
return RCREG;
}
void Serial_TX(unsigned char a){
TXREG=a;
while (TRMT==0);
}