Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
318 kaklik 1
'robot
2
 
3
'#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
4
 
5
 
6
#pragma DATA _CONFIG1H, _OSCS_OFF_1H & _HSPLL_OSC_1H
7
#pragma DATA _CONFIG2L, _BOR_ON_2L & _BORV_42_2L & _PWRT_ON_2L
8
#pragma DATA _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
9
#pragma DATA _CONFIG3H, _CCP2MX_OFF_3H
10
#pragma DATA _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
11
#pragma DATA _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L
12
#pragma DATA _CONFIG5H, _CPB_ON_5H & _CPD_ON_5H
13
#pragma DATA _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
14
#pragma DATA _CONFIG6H, _WRTC_ON_6H & _WRTB_ON_6H & _WRTD_OFF_6H
15
#pragma DATA _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
16
#pragma DATA _CONFIG7H, _EBTRB_ON_7H
17
 
18
#pragma CLOCK_FREQ 40000000
19
 
20
Function receive() As Byte
21
	If ( (rcsta.OERR = 1) ) Then
22
		rcsta.CREN = 0
23
        rcsta.CREN = 1
24
	End If
25
    Do While (pir1.RCIF = 0)
26
	Loop
27
	receive = rcreg
28
 
29
End Function
30
 
31
Sub send(c As Byte)
32
	Do while (pir1 & (1 << TXIF)) = 0 Loop
33
	txreg = c
34
End Sub
35
 
36
Sub main()
37
	Dim motors As Byte
38
	Dim sensors As Byte
39
	Dim leds As Byte
40
	Dim leds1 As Byte
41
	Dim buttons As Byte
42
	Dim i As Long
43
 
44
	'NASTAVENI IO
45
	lata=0xFF
46
	latb=0
47
	latc=0xFF
48
	trisa=0xF0
49
	trisb=0x3F
50
	trisc=0x9F
51
 
52
	'VYPNOUT ADC
53
	adcon1=0xC6
54
	adcon0=0xC0
55
 
56
	'UART 9600bps
57
	spbrg=64
58
	txsta = txsta & ~(1 << BRGH)
59
	txsta = txsta | (1 << TXEN)
60
	rcsta = rcsta | (1 << CREN)
61
	rcsta = rcsta | (1 << SPEN)
62
 
63
 
64
	leds = 0xFF
65
	leds1 = 0x0F 
66
 
67
	motors = 0x00
68
 
69
Do while 1
70
 
71
		buttons = portb
72
 
73
		If (buttons.1)=0 Then
74
			i=0
75
			leds1 = leds1 - 1
76
			lata = leds1
77
			Do while i <= 500000
78
			i=i+1
79
			loop
80
			motors = motors + 0x11
81
 
82
		elseif (buttons.4)=0 Then
83
			i=0
84
			leds1 = leds1 + 1
85
			lata = leds1
86
			Do while i <= 500000
87
			i=i+1
88
			loop
89
			motors = motors - 0x11
90
		End If
91
 
92
		leds = 0xFF
93
		sensors =0xFF 
94
		sensors = Call receive()	'prijmi stav cidel senzoru
95
		'Bity v bajtu sensors
96
		'BIT3=LEVE SPODNI, BIT2=PRAVE SPODNI, BIT1=LEVE PREDNI, BIT0=PRAVE PREDNI
97
		'prislusny bit v nule znamena aktivni senzor
98
		If (sensors.0)=0 Then
99
			'pravy predni senzor aktivni
100
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
101
			leds = leds & ~(1 << 1)	'led sviti, kdyz se ji bit znuluje
102
		End If
103
 
104
		If (sensors.1)=0 Then
105
			'levy predni senzor aktivni
106
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
107
			leds = leds & ~(1 << 2)	'led sviti, kdyz se ji bit znuluje
108
		End If
109
 
110
		If (sensors.2)=0 Then
111
			'pravy spodni senzor aktivni
112
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
113
			leds = leds & ~(1 << 0)	'led sviti, kdyz se ji bit znuluje
114
		End If
115
 
116
		If (sensors.3)=0 Then
117
			'levy spodni senzor aktivni
118
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
119
			leds = leds & ~(1 << 3)	'led sviti, kdyz se ji bit znuluje
120
		End If 
121
 
122
 
123
	lata = leds
124
	call send(motors)
125
 
126
 
127
	Loop
128
 
129
 
130
End Sub