Escolar Documentos
Profissional Documentos
Cultura Documentos
Com Zigbee
Com Zigbee
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
=
=
=
=
0b00001111;
0b10111001;
0x00;
0b00000100;
OpenUSART(
// RC7: Rx e RC6:Tx
USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH, 25 );
RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PIR1bits.RCIF = 0;
inicia_lcd();
while(1)
//Loop principal
{
while((PORTB | 0xF0) == 0xFF)
{
if(new_dt)
{
new_dt = 0;
if(rx_dt != '0')
escreve_dado(rx_dt);
else
{
escreve_comando(0xC3);
//for...
escreve_dado('X');
escreve_dado('X');
escreve_dado('X');
1
}
}
}
Delay1KTCYx(20);
//Delay para debounce das teclas
if((PORTB | 0xF0) == 0b11111110)
WriteUSART('0');
else if((PORTB | 0xF0) == 0b11111101)
WriteUSART('1');
else if((PORTB | 0xF0) == 0b11111011)
WriteUSART('2');
else if((PORTB | 0xF0) == 0b11110111)
WriteUSART('3');
while((PORTB | 0xF0) != 0xFF){}
Delay1KTCYx(30);
//Delay para debounce das teclas
while((PORTB | 0xF0) != 0xFF){}
}
}
//---------------------------------------------------------------//Envia comando para o LCD
void escreve_comando(char c)
{
PORTEbits.RE0=0;
PORTD=c;
Delay10TCYx(1);
PORTEbits.RE1=1;
Delay1TCY();
Delay1TCY();
Delay1TCY();
PORTEbits.RE1=0;
Delay1KTCYx(1);
}
//---------------------------------------------------------------//Escrita de uma dado no LCD
void escreve_dado(char d)
{
PORTEbits.RE0=1;
PORTD=d;
Delay10TCYx(1);
PORTEbits.RE1=1;
Delay1TCY();
Delay1TCY();
Delay1TCY();
PORTEbits.RE1=0;
Delay1KTCYx(1);
PORTEbits.RE0=1;
}
//---------------------------------------------------------------//Funo de inicializao do LCD
void inicia_lcd(void)
{
escreve_comando(0x38);
Delay1KTCYx(3);
escreve_comando(0x38);
escreve_comando(0x06);
escreve_comando(0x0C);
escreve_comando(0x01);
Delay1KTCYx(1);
escreve_comando(0x80); //Posiciona cursor
escreve_dado('.');
escreve_comando(0xC0);
escreve_dado('R');
escreve_dado('X');
escreve_dado(':');
}