Subversion Repositories svnkaklik

Rev

Rev 324 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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