Subversion Repositories svnkaklik

Rev

Rev 318 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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