Subversion Repositories svnkaklik

Rev

Rev 319 | Go to most recent revision | Details | Compare with Previous | 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
 
320 kaklik 71
  Do while i <= 500000
72
    i=i+1
73
	loop
74
  motors = motors + 0x11
318 kaklik 75
 
76
		elseif (buttons.4)=0 Then
77
			i=0
78
			leds1 = leds1 + 1
79
			lata = leds1
80
			Do while i <= 500000
81
			i=i+1
82
			loop
83
			motors = motors - 0x11
84
		End If
85
 
86
		leds = 0xFF
87
		sensors =0xFF 
88
		sensors = Call receive()	'prijmi stav cidel senzoru
89
		'Bity v bajtu sensors
90
		'BIT3=LEVE SPODNI, BIT2=PRAVE SPODNI, BIT1=LEVE PREDNI, BIT0=PRAVE PREDNI
91
		'prislusny bit v nule znamena aktivni senzor
92
		If (sensors.0)=0 Then
93
			'pravy predni senzor aktivni
94
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
95
			leds = leds & ~(1 << 1)	'led sviti, kdyz se ji bit znuluje
96
		End If
97
 
98
		If (sensors.1)=0 Then
99
			'levy predni senzor aktivni
100
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
101
			leds = leds & ~(1 << 2)	'led sviti, kdyz se ji bit znuluje
102
		End If
103
 
104
		If (sensors.2)=0 Then
105
			'pravy spodni senzor aktivni
106
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
107
			leds = leds & ~(1 << 0)	'led sviti, kdyz se ji bit znuluje
108
		End If
109
 
110
		If (sensors.3)=0 Then
111
			'levy spodni senzor aktivni
112
			'rozsvit prislusnou LED k senzoru, zatim jen v promenne
113
			leds = leds & ~(1 << 3)	'led sviti, kdyz se ji bit znuluje
114
		End If 
115
 
116
 
117
	lata = leds
118
	call send(motors)
119
 
120
 
121
	Loop
122
 
123
 
124
End Sub