-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.c
More file actions
82 lines (68 loc) · 1.46 KB
/
ex2.c
File metadata and controls
82 lines (68 loc) · 1.46 KB
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
/*
* File: ex2.c
* Author: alex
*
* Created on February 24, 2022, 9:09 AM
*/
#include <xc.h>
#include <pic18f8722.h>
#include "config_bits.h"
#include "fonctions_LCD.h"
#define _XTAL_FREQ 10000000
#include <stdio.h>
// exercice 1
int temp = 30;
void initPortTOR()
{
TRISD = 0; // RD0 en sortie
TRISBbits.TRISB0 = 1; //RB0 en entree
TRISAbits.TRISA5 = 1; //RB0 en entree
ADCON1 = 0b00001110; // vref+/vref- = vdd/vss RA0 entre ana Ra1-Ra7 IO TOR
}
int testBtnPressed()
{
if(temp < 40 || temp >= 20){
if(PORTBbits.RB0 == 0 || PORTAbits.RA5 == 0) // RD0 appuye)
{
__delay_ms(20);
if(PORTBbits.RB0 == 0)
{
temp++;
}
else
{
if(PORTAbits.RA5 == 0)
{
temp--;
}
}
}
return temp;
}
}
void ex2(void)
{
int L_ret = 0;
initPortTOR();
lcdInit();
while(1) //boucle infinie
{
L_ret = testBtnPressed();
//led allumée
PORTD= L_ret % 10 ;
lcdGoToLC(1,0);
switch(L_ret)
{
case 1:
LCDPutStr("Btn 1 ON ");
break;
case 2:
LCDPutStr("Btn 2 ON ");
break;
default :
LCDPutStr("Btn 1 et 2 OFF ");
break;
}
__delay_ms(100);
}
}