Subversion Repositories svnkaklik

Rev

Rev 322 | 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 buttons As Byte
322 kaklik 40
	Dim leds As Byte
323 kaklik 41
	Dim count As Byte
318 kaklik 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
 
321 kaklik 63
	motors = 0x00
322 kaklik 64
 
65
    do while (portb.0 = 1)
66
	loop
67
 
68
	leds = 0xF0
69
	count = 400000
318 kaklik 70
 
322 kaklik 71
	do while (count > 0)
72
		count = count -1
73
 
74
		if count < 300000 then
75
			leds = leds | 1
76
		end if
77
		if count < 200000 then
78
			leds = leds | 2
79
		end if
80
		if count < 100000 then
81
			leds = leds | 4
82
		end if
83
		lata = leds
84
	loop
85
	leds = 0xFF
86
	lata = 0xFF
318 kaklik 87
 
88
 
89
Do while 1
90
 
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
99
    motors = 0xF7
100
  End If
318 kaklik 101
 
321 kaklik 102
  If (!(sensors.3)) Then
103
    motors = 0x7F
104
  End If 
105
 
106
  lata = sensors
107
  call send(motors)
318 kaklik 108
 
321 kaklik 109
Loop
110
 
318 kaklik 111
End Sub