Rev 320 | Blame | Last modification | View Log | Download
'robot'#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H#pragma DATA _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H#pragma DATA _CONFIG2L, _BOR_ON_2L & _BORV_42_2L & _PWRT_ON_2L#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H#pragma DATA _CONFIG3H, _CCP2MX_OFF_3H#pragma DATA _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L#pragma DATA _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L#pragma DATA _CONFIG5H, _CPB_ON_5H & _CPD_ON_5H#pragma DATA _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L#pragma DATA _CONFIG6H, _WRTC_ON_6H & _WRTB_ON_6H & _WRTD_OFF_6H#pragma DATA _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L#pragma DATA _CONFIG7H, _EBTRB_ON_7H#pragma CLOCK_FREQ 40000000Function receive() As ByteIf ( (rcsta.OERR = 1) ) Thenrcsta.CREN = 0rcsta.CREN = 1End IfDo While (pir1.RCIF = 0)Loopreceive = rcregEnd FunctionSub send(c As Byte)Do while (pir1 & (1 << TXIF)) = 0 Looptxreg = cEnd SubSub delay(cas As Byte)Dim i As ByteDim x As ByteDo while i <= casDo While x <= 100Call receive()x=x+1loopi=i+1loopEnd SubSub main()Dim motors As ByteDim sensors As ByteDim buttons As ByteDim i As Long'NASTAVENI IOlata=0xFFlatb=0latc=0xFFtrisa=0xF0trisb=0x3Ftrisc=0x9F'VYPNOUT ADCadcon1=0xC6adcon0=0xC0'UART 9600bpsspbrg=64txsta = txsta & ~(1 << BRGH)txsta = txsta | (1 << TXEN)rcsta = rcsta | (1 << CREN)rcsta = rcsta | (1 << SPEN)motors = 0x00lata = 0x0ECall delay(200)lata = 0x0DCall delay(200)lata = 0x0BCall delay(200)lata = 0x07Call delay(200)motors = 0x77Call delay(100)Do while 1sensors =0xFFsensors = Call receive() 'prijmi stav cidel senzoruIf (!((sensors.0) and (sensors.1))) Thenmotors = 0x77End IfIf (!(sensors.2)) Thenmotors = 0xF7End IfIf (!(sensors.3)) Thenmotors = 0x7FEnd Iflata = sensorscall send(motors)LoopEnd Sub