Vous êtes sur la page 1sur 7

https://www.youtube.com/watch?

v=gziSp9MJkSA&list=PL2FC997C3EE00D77C&index=1
http://www.engbedded.com/cgi-bin/fcx.cgi?P_PREV=ATmega328P&P=ATmega328P&M_LOW_0x
3F=0x22&M_LOW_0x80=0x00&M_HIGH_0x06=0x00&M_HIGH_0x20=0x00&M_EXTENDED_0x07=0x07&B
_CKDIV8=P&B_SPIEN=P&B_SUT0=P&B_CKSEL3=P&B_CKSEL2=P&B_BOOTSZ1=P&B_BOOTSZ0=P&B_CKS
EL0=P&V_LOW=62&V_HIGH=D9&V_EXTENDED=FF&O_DEFAULT=Defaults
http://www.jayconsystems.com/tutorial/atmerpt1/
filho olhe para o ceu, as estrelas a brilhar
Em meio a escuridao pra nos confortar
E quando andamos pela noite, veja essa luz
O amor que ha em mim, nesta cano de ninar
papai no dorme
papai no se cana
no me assusto se troveja
pois estou com meu pai
papai nao dorme
papai nao se cana
nao me assusto se troveja
pois estou no colo do papai
Quando olho para o ceu, ouo uma voz
Em meu coracao jamais te deixarei
Preciso entender, que onde quer que eu va
Estou em tuas maos no controle tu estas
papai no dorme
papai no se cana
no me assusto se troveja
pois estou com meu pai
papai nao dorme
papai nao se cana
nao me assusto se troveja
pois estou no colo do papai
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_RW at RB6_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_RW_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
#define SCL_SCK RC3
#define SDA_SDI RC4
#define HIGH_SPEED 400000 //400kHz 400kBps
#define NORNAL_SPEED 100000 //100kHz 100kBps
void I2CWait() {
while ((SSPCON2 & 0x1F) || (SSPSTAT & 0x04)); /* wait for any pending transf
er */
}
void I2CStart() {
I2CWait();
SSPCON2.SEN = 1;
while(SSPCON2.SEN);
}
void I2CRestart() {
I2CWait();
SSPCON2.RSEN = 1;
while(SSPCON2.RSEN);
}
void I2C_W(char address) {
I2CWait();
SSPBUF = address;
while(SSPSTAT.BF);
I2CWait();
if(!SSPCON2.ACKSTAT) PORTA.F0 =~ PORTA.F0;
}
unsigned char I2CReceive() {
I2CWait();
SSPCON2.RCEN = 1;
while(!SSPSTAT.BF);
return SSPBUF;
}
void I2CACK() {
I2CWait();
SSPCON2.ACKEN = 1;
while(SSPCON2.ACKEN);
}
void I2CStop() {
I2CWait();
SSPCON2.PEN = 1;
while(SSPCON2.PEN);
}
void I2C_Config() {
SSPCON1 = 0b00101000; //WCOL/SSPOV/SSPEN/CKP/SSPM3/SSPM2/SSPM1/SSPM0
SSPSTAT = 0b01000000; //SMP/CKE/DA/P/S/RW/UA/BF
I2C1_Init(NORNAL_SPEED);
SSPADD = 49; //Clock = 100KHz SSPCON = 0b00101000; I2C Mast
er mode, clock = FOSC / (4 * (SSPADD+1))
}
/*
//24C02B
delay_ms(250);
I2CStart();
delay_us(4);
I2CSend(0xA0);
I2CSend(0x10);
I2CSend(0x25);
I2CStop();
delay_us(4);
I2CStart();
delay_us(4);
I2CSend(0xA0);
I2CSend(0x10);
I2CRestart();
delay_us(4);
I2CSend(0xA0+1);
PORTB=I2CReceive();
I2CStop();
delay_us(4);
*/
/*
// TC74
delay_ms(250);
I2CStart();
delay_us(4);
I2C1_Wr(0x9A);
I2C1_Wr(0x00);
I2C1_Repeated_Start();
delay_us(4);
I2C1_Wr(0x9B);
PORTB = I2C1_Rd();
I2C1_Stop();
delay_us(4);
*/
/*
// MCP3221
delay_ms(250);
I2CStart();
delay_us(4);
I2CSend(0x90+1);
PORTB=I2CReceive();
I2CACK();
PORTD=I2CReceive();
I2CStop();
*/
/*
// DS1621
delay_ms(250);
I2CStart();
I2CSend(0x92);
I2CSend(0xEE);
I2CRestart();
I2CSend(0x92);
I2CSend(0xAA);
I2CRestart();
I2CSend(0x92+1);
PORTB=I2CReceive();
I2CACK();
PORTD=I2CReceive();
I2CStop();
*/
unsigned short sec = 0;
/*
void interrupt() {
//Interrupcao de EEPROM
if(EEIF_bit == 1) {
RD3_bit = 1;
EEIF_bit = 0;
}
}
void ISR() {
//Interrupcao de TMR0
if(TMR1IE_bit == 1 && TMR1IF_bit == 1) {
sec++;
Lcd_Out(3,1,"3");
if(sec == 2) {
RD3_bit =~ RD3_bit;
sec = 0;
Lcd_Out(4,1,"4");
}
TMR1IF_bit = 0;
TMR0H = 0X0B;
TMR0L = 0XDC;
}
}
void Timer1_Config() {
T1CON = 0b10111000; //RD16/T1RUN/T1CKPS1/T1CKPS0/T1OSCEN/T1SYNC/TMR1CS/TMR1O
N
TMR1H = 0X0B;
TMR1L = 0XDC;
TMR1IF_bit = 0;
TMR1ON_bit = 1;
Lcd_Out(2,1,"2");
TMR1ON_bit = 1;
}
*/
//IPR2 = 0b00010000; //OSCFIP/CMIP//EEIP/BCLIP/HLVDIP/TMR3IP/CCP2IP
//PIE1 = 0b00000001; //PSPIF/ADIF/RCIF/TXIF/SSPIF/CCP1IF/TMR2IF/TMR1IE
//IPR1 = 0b00000000; //PSPIP/ADIP/RCIP/TXIP/SSPIP/CCP1IP/TMR2IP/TMR1IP
//PIR1 = 0b00000000; //PSPIF/ADIF/RCIF/TXIF/SSPIF/CCP1IF/TMR2IF/TMR1IF
Ler_Set_Temp:
Lcd_Out(1, 1, "Set Temp: ");
//Exibe Setpoint Temperatura salvo na EEPROM
WREN_bit = 0; //Desabilita ciclo de escrita
na EEPROM
EECON1 = 0b00000001; //EEPGD= 0 / CFGS= 0 /
? / FREE= 0 / WRERR= 0 / WREN= 0 / WR= 0 / RD= 1 //Habilita Leitura EEPROM
if (EEIE_bit == 1 && EEPGD_bit == 0 && CFGS_
bit == 0 && WREN_bit == 0 && WR_bit == 0) {
EEADR = id_ee_sp_temp;
EEDATA = EEPROM_Read(EEADR);
read_ee_sp_temp = EEDATA;
chr_ee_sp_temp[0] = (((read_ee_sp_temp /
100) % 10) + 48); //centena
chr_ee_sp_temp[1] = (((read_ee_sp_temp /
10) % 10) + 48); //dezena
chr_ee_sp_temp[2] = ((read_ee_sp_temp %
10) + 48); //unidade
Lcd_Chr_CP(chr_ee_sp_temp[0]);
Lcd_Chr_CP(chr_ee_sp_temp[1]);
Lcd_Chr_CP('.');
Lcd_Chr_CP(chr_ee_sp_temp[2]);
Lcd_Out_CP(" *C");
EEIF_bit = 0;
}
//Incrementa valor Setpoint Temperatura
if (Button(&PORTD, B_UP, deboucy, 0)) {
if (sp_temp <= sp_min_temp) sp_temp = sp
_min_temp; //Trava Setpoint temperatura no limite minimo permitido
if (sp_temp > sp_min_temp) sp_temp--;
}
//Decrementa valor Setpoint Temperatura
if (Button(&PORTD, B_DOWN, deboucy, 0)) {
if (sp_temp >= sp_max_temp) sp_temp = sp
_max_temp; //Trava Setpoint temperatura no limite maximo permitido
if (sp_temp < sp_max_temp) sp_temp++;
}
//Exibe valor Setpoint Temperatura alterado
++ ou --
Lcd_Out(2, 1, "Inc/Dec: ");
chr_sp_temp[0] = (((sp_temp / 100) % 10) + 4
8); //centena
chr_sp_temp[1] = (((sp_temp / 10) % 10) + 4
8); //dezena
chr_sp_temp[2] = ((sp_temp % 10) + 48);
//unidade
Lcd_Chr_CP(chr_sp_temp[0]);
Lcd_Chr_CP(chr_sp_temp[1]);
Lcd_Chr_CP('.');
Lcd_Chr_CP(chr_sp_temp[2]);
Lcd_Out_CP(" *C");
if (Button(&PORTD, B_ENTER, deboucy, 1)) {
static bit sp_temp_flag;
sp_temp_flag = 1;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Entre com a Senha");

do {
//Incrementa valor Senha
if (Button(&PORTD, B_UP, deboucy, 0)
) {
if (check_passwd <= passwd_min)
check_passwd = passwd_min; //Trava Senha no limite minimo permitido
if (check_passwd > passwd_min) c
heck_passwd--;
}
//Decrementa valor Senha
if (Button(&PORTD, B_DOWN, deboucy,
0)) {
if (check_passwd >= passwd_max)
check_passwd = passwd_max; //Trava Senha no limite maximo permitido
if (check_passwd < passwd_max) c
heck_passwd++;
}
Lcd_Out(2, 1, "Senha: ");
chr_passwd[0] = (((check_passwd / 10
0) % 10) + 48); //centena
chr_passwd[1] = (((check_passwd / 10
) % 10) + 48); //dezena
chr_passwd[2] = ((check_passwd % 10
) + 48); //unidade
Lcd_Chr_CP(chr_passwd[0]);
Lcd_Chr_CP(chr_passwd[1]);
Lcd_Chr_CP(chr_passwd[2]);
//Compara senha alterada com gravada
na EEPROM
if (Button(&PORTD, B_ENTER, deboucy,
1)) {
WREN_bit = 0; //Desabil
ita ciclo de escrita EEPROM
EECON1 = 0b00000001; //EEPGD/C
FGS/-/FREE/WRERR/WREN/WR/RD
if (EEIE_bit == 1 && EEPGD_bit =
= 0 && CFGS_bit == 0 && WREN_bit == 0 && WREN_bit == 0 && WR_bit == 0) {
EEADR = id_ee_passwd;
EEDATA = EEPROM_Read(EEADR);
read_ee_passwd = EEDATA;
//Senha correta
if (check_passwd == read_ee_
passwd) {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(3, 4, "Senha cor
reta");
EEIF_bit = 0;
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
EEADR = id_ee_sp_temp;
EEDATA = sp_temp;
WR_EEPROM(EEADR, EEDATA)
;
Delay_ms(1000);

//Setpoint Temperatura
salvo com sucesso na EEPROM
if(success) {
Lcd_Cmd(_LCD_CLEA
R);
WREN_bit = 0; //D
esabilita ciclo de escrita EEPROM
Lcd_Out(3, 1, "Se
t Salvo!");
Delay_ms(1000);
goto Ler_Set_Temp
; //Salta no inicio do metodo lendo a temperatura da EEPROM
}

//Erro ao salvar Set
point Temperatura na EEPROM
else if(fail) {
Lcd_Cmd(_LC
D_CLEAR);
WREN_bit =
0; //Desabilita ciclo de escrita EEPROM
EEIF_bit =
0; //Limpa flag da EEPROM
INTCON = 0b
11000000; //Carrega estado previo salvo de INTCON
Lcd_Out(3,
1, "Erro ao Salvar!");
Delay_ms(10
00);
}
sp_temp_flag = 0;
}
//Senha errada
else {
EEIF_bit = 0;
Lcd_Out(3, 5, "Senha err
ada");
Delay_ms(1000);
}
}
}
} while (sp_temp_flag);
}
//Sair SetPoint Temperatura
if(Button(&PORTD, B_ESC, deboucy, 1)) {
EEIE_bit = 1;
EEIF_bit = 0;
//Limpa flag da EEPROM
INTCON = 0b11000000;
//Carrega estado previo salvo de INTCON
cursor_par_ctrl = 1;
op_par_ctrl = 0;
Lcd_Cmd(_LCD_CLEAR);
}

Vous aimerez peut-être aussi