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 buttons As Byte
322 kaklik 40
	Dim leds As Byte
324 kaklik 41
	Dim count As Long
325 kaklik 42
	Dim cas As Long
318 kaklik 43
	Dim i As Long
44
 
45
	'NASTAVENI IO
46
	lata=0xFF
47
	latb=0
48
	latc=0xFF
49
	trisa=0xF0
50
	trisb=0x3F
51
	trisc=0x9F
52
 
53
	'VYPNOUT ADC
54
	adcon1=0xC6
55
	adcon0=0xC0
56
 
57
	'UART 9600bps
58
	spbrg=64
59
	txsta = txsta & ~(1 << BRGH)
60
	txsta = txsta | (1 << TXEN)
61
	rcsta = rcsta | (1 << CREN)
62
	rcsta = rcsta | (1 << SPEN)
63
 
321 kaklik 64
	motors = 0x00
322 kaklik 65
 
66
    do while (portb.0 = 1)
67
	loop
68
 
69
	leds = 0xF0
70
	count = 400000
318 kaklik 71
 
322 kaklik 72
	do while (count > 0)
73
		count = count -1
74
 
75
		if count < 300000 then
76
			leds = leds | 1
77
		end if
78
		if count < 200000 then
79
			leds = leds | 2
80
		end if
81
		if count < 100000 then
82
			leds = leds | 4
83
		end if
84
		lata = leds
85
	loop
86
	lata = 0xFF
318 kaklik 87
 
88
 
89
Do while 1
325 kaklik 90
  cas = 0
321 kaklik 91
  sensors =0xFF 
92
  sensors = Call receive()	'prijmi stav cidel senzoru
318 kaklik 93
 
321 kaklik 94
  If (!((sensors.0) and (sensors.1))) Then
95
    motors = 0x77
96
  End If
97
 
98
  If (!(sensors.2)) Then
325 kaklik 99
    If cas< 400000 Then
100
      cas = cas + 1
101
    End If
102
    cas = 0
321 kaklik 103
    motors = 0xF7
104
  End If
318 kaklik 105
 
321 kaklik 106
  If (!(sensors.3)) Then
325 kaklik 107
    If cas< 400000 Then
108
      cas = cas + 1
109
    End If
110
    cas = 0
321 kaklik 111
    motors = 0x7F
112
  End If 
325 kaklik 113
 
114
  cas = cas+1			
321 kaklik 115
  lata = sensors
116
  call send(motors)
318 kaklik 117
 
321 kaklik 118
Loop
119
 
318 kaklik 120
End Sub