Você está na página 1de 2

C:\Documents and Settings\rromano\Meus documentos\EEM\ECA207\4oBim\zigbee\Firmware\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

// Firmware desenvolvido para o hardware da placa McLabII - comunicao serial


#include<p18f452.h>
#include<delays.h>
#include<usart.h>
#pragma config WDT = OFF, LVP = OFF, OSC = XT, PWRT = ON, BOR = ON, BORV = 42
//Prottipos de funes
void ISR_High_Priority(void);
void inicia_lcd(void);
void escreve_comando(char c);
void escreve_dado(char d);

//Funo de inicializao do LCD


//Envia comando para o LCD
//Escrita de uma dado no LCD

//Definio de variveis globais


volatile unsigned char new_dt, rx_dt = 0;
//---------------------------------------------------------------#pragma code vec_int_high_priority = 0x08
void vec_int_high_priority(void)
{ _asm GOTO ISR_High_Priority _endasm }
#pragma interrupt ISR_High_Priority
void ISR_High_Priority(void)
{
if(PIR1bits.RCIF)
{
rx_dt = ReadUSART();
new_dt = 1;
PIR1bits.RCIF = 0;
}
}
//---------------------------------------------------------------void main(void)
{
PORTB = 0x00;
PORTD = 0x00;
ADCON1 = 0x07;
TRISB
TRISC
TRISD
TRISE

=
=
=
=

0b00001111;
0b10111001;
0x00;
0b00000100;

OpenUSART(

// PORTA como pinos digitais

// 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 );

// Int. de transmisso habilitada


// Int. de recepo habilitada
// Comunicao assncrona
// Recepo contnua
// Alta velocidade 9600bps

RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;

//Habilita prioridade de interrupes


//Int. USART (RX) de alta prioridade
//Habilita interrupes
//Habilita interrupes de perifricos

PIR1bits.RCIF = 0;
inicia_lcd();

//Inicializa flag de interrupes

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

C:\Documents and Settings\rromano\Meus documentos\EEM\ECA207\4oBim\zigbee\Firmware\com_zigbee.c


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

}
}
}
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(':');
}

Você também pode gostar