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 main()Dim motors As ByteDim sensors As ByteDim leds As ByteDim leds1 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)leds = 0xFFleds1 = 0x0Fmotors = 0x00Do while 1buttons = portbIf (buttons.1)=0 Theni=0leds1 = leds1 - 1lata = leds1Do while i <= 500000i=i+1loopmotors = motors + 0x11elseif (buttons.4)=0 Theni=0leds1 = leds1 + 1lata = leds1Do while i <= 500000i=i+1loopmotors = motors - 0x11End Ifleds = 0xFFsensors =0xFFsensors = Call receive() 'prijmi stav cidel senzoru'Bity v bajtu sensors'BIT3=LEVE SPODNI, BIT2=PRAVE SPODNI, BIT1=LEVE PREDNI, BIT0=PRAVE PREDNI'prislusny bit v nule znamena aktivni senzorIf (sensors.0)=0 Then'pravy predni senzor aktivni'rozsvit prislusnou LED k senzoru, zatim jen v promenneleds = leds & ~(1 << 1) 'led sviti, kdyz se ji bit znulujeEnd IfIf (sensors.1)=0 Then'levy predni senzor aktivni'rozsvit prislusnou LED k senzoru, zatim jen v promenneleds = leds & ~(1 << 2) 'led sviti, kdyz se ji bit znulujeEnd IfIf (sensors.2)=0 Then'pravy spodni senzor aktivni'rozsvit prislusnou LED k senzoru, zatim jen v promenneleds = leds & ~(1 << 0) 'led sviti, kdyz se ji bit znulujeEnd IfIf (sensors.3)=0 Then'levy spodni senzor aktivni'rozsvit prislusnou LED k senzoru, zatim jen v promenneleds = leds & ~(1 << 3) 'led sviti, kdyz se ji bit znulujeEnd Iflata = ledscall send(motors)LoopEnd Sub