-
Notifications
You must be signed in to change notification settings - Fork 0
/
carrera.c
195 lines (138 loc) · 4.56 KB
/
carrera.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// PIC16F887 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1
#pragma config FOSC = INTRC_NOCLKOUT// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)
// CONFIG2
#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
/*
*
* File: carrera.c
* Author: mario
*
* Created on 31 de enero de 2021, 09:06 PM
*/
#include <xc.h>
void setup (void);
void semaforo(void);
void delay(unsigned char n);
void jugador1(unsigned char j1);
void jugador2(unsigned char j2);
//deinimos nuestro tiepo para 4Mhz
#define _XTAL_FREQ 4000000
#define lverde PORTBbits.RB0
#define lamarillo PORTBbits.RB1
#define lrojo PORTBbits.RB2
unsigned char j1;
unsigned char j2;
void main(void) {
setup();
delay(1000);
while(1){
if (PORTAbits.RA0 == 0){
semaforo();
}
}
return;
}
void delay(unsigned char n) {
for (int i = 0; i < 255; i++) {
for (int j = 0; j < 255; j++) {
}
}
}
void setup (void) {
ANSEL = 0;
ANSELH = 0;
TRISB = 0;//LEDS SEMAFORO
TRISC = 0;//LEDS J1
TRISD = 0;//LEDS J2
TRISA = 0b00000111; //Botones
//LIMPIAMOS PUERTOS
PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
}
void semaforo (void){
lverde = 0;
lamarillo = 0;
lrojo = 1;
delay(1000);
lverde = 0;
lamarillo = 1;
lrojo = 0;
delay(1000);
lverde = 1;
lamarillo = 0;
lrojo = 0;
delay(1000);
}
void jugador1(unsigned char j1){
if (j1 == 8){
PORTBbits.RB3 = 1;
delay(1000);
switch(j1){
case 1:
PORTCbits.RC0 = 1;
break;
case 2:
PORTCbits.RC1 = 1;
case 3:
PORTCbits.RC2 = 1;
break;
case 4:
PORTCbits.RC3 = 1;
case 5:
PORTCbits.RC4 = 1;
break;
case 6:
PORTCbits.RC5 = 1;
case 7:
PORTCbits.RC6 = 1;
break;
case 8:
PORTCbits.RC3 = 1;
}
}
}
void jugador2(unsigned char j2){
if (j2 == 8){
PORTBbits.RB4 = 1;
delay(1000);
switch(j2){
case 1:
PORTDbits.RD0 = 1;
break;
case 2:
PORTDbits.RD1 = 1;
case 3:
PORTDbits.RD2 = 1;
break;
case 4:
PORTDbits.RD3 = 1;
case 5:
PORTCbits.RC4 = 1;
break;
case 6:
PORTDbits.RD5 = 1;
case 7:
PORTDbits.RD6 = 1;
break;
case 8:
PORTDbits.RD3 = 1;
}
}
}