Sie sind auf Seite 1von 15

http://www.edaboard.com/thread284335.

html
http://pt.scribd.com/doc/199324519/Cortex-m-Series
http://www.mikroe.com/forum/viewtopic.php?t=17449
https://www.youtube.com/watch?v=v1dLdfa-7Yw
http://saeedsolutions.blogspot.com.br/2012/10/pic16f84a-pwm-code-proteus-simulat
ion.html
// Constants for calculating temperature and humidity
// SHT1x / SHT7x V4 humidity conversion coefficients (12 bits)
const unsigned int C1 = 205;
// -2.0468
const unsigned int C2 = 367;
// 0.0367 (367 * 10^-4)
const unsigned short C3 = 16;
// -1.5955* 10^-6 (15.955 * 10^-7)
//SHT1x / SHT7x V4 temperature compensation coefficients (12 bits)
const unsigned int T1 = 1000;
// 0.01 (1*10^-2)
const unsigned int T2 = 8;
// 0.00008 (8 * 10^-5)
//SHT1x V4 temperature conversion coefficients (14 bits)
const unsigned int D1 = 4010;
// -40.1
const unsigned short D2 = 1;
// 0.01
unsigned short i, j, Select;
long int temp, k, SOt, SOrh, Tmp_res, Rh_res;
char *Tmp = "000.0 ";
char *Rh = "00.0 ";
void SHT_Reset() {
if(Select == 1) {
SCL_SCK = 0;
SDA_SDI = 1;
for (i = 1; i <= 10; i++)
SCL_SCK = ~SCL_SCK;
}
}

//
//
//
//

SCL low
define SDA as input
repeat 10 times
invert SCL

void Transmission_Start()
if(Select == 1) {
SDA_SDI_Direction
SCL_SCK = 1;
Delay_1us();
SDA_SDI_Direction
SDA_SDI = 0;
Delay_1us();
SCL_SCK = 0;
Delay_1us();
SCL_SCK = 1;
Delay_1us();
SDA_SDI_Direction
Delay_1us();
SCL_SCK = 0;
}
}

//
//
//
//
//
//
//
//
//
//
//
//
//

define SDA as input


SCL high
1us delay
define SDA as output
SDA low
1us delay
SCL low
1us delay
SCL high
1us delay
define SDA as input
1us delay
SCL low

// MCU ACK
void MCU_ACK() {
if(Select == 1) {

{
= 1;
= 0;

= 1;

SDA_SDI_Direction = 0;
SDA_SDI = 0;
SCL_SCK = 1;
Delay_1us();
SCL_SCK = 0;
Delay_1us();
SDA_SDI_Direction = 1;

//
//
//
//
//
//
//

define SDA as output


SDA low
SCL high
1us delay
SCL low
1us delay
define SDA as input

}
}
// This function returns temperature or humidity, depends on command
long int Measure(short command) {
j = command;
// j = command (0x03 or 0x05)
SHT_Reset();
// procedure for reseting SHT11
Transmission_Start();
// procedure for sTmprting transmission
k = 0;
// k = 0
if(Select == 1) {
SDA_SDI_Direction = 0;
// define SDA as output
SCL_SCK = 0;
// SCL low
for(i = 1; i <= 8; i++) {
// repeat 8 times
if (j.F7 == 1)
// if bit 7 = 1
SDA_SDI_Direction = 1;// define SDA as input
else {
// else (if bit 7 = 0)
SDA_SDI_Direction = 0;// define SDA as output
SDA_SDI = 0;
// SDA low
}
Delay_1us();
// 1us delay
SCL_SCK = 1;
// SCL high
Delay_1us();
// 1us delay
SCL_SCK = 0;
// SCL low
j <<= 1;
// move contents of j one place left
}
SDA_SDI_Direction = 1;
SCL_SCK = 1;
Delay_1us();
SCL_SCK = 0;
Delay_1us();
while (SDA_SDI == 1)
Delay_1us();

//
//
//
//
//
//
//

define SDA as input


SCL high
1us delay
SCL low
1us delay
while SDA is high, do nothing
1us delay

for (i = 1; i <=16; i++) {


k <<= 1;
SCL_SCK = 1;
if (SDA_SDI == 1)
k = k | 0x0001;
SCL_SCK = 0;
if (i == 8)
MCU_ACK();
}

//
//
//
//

repeat 16 times
move contents of k one place left
SCL high
if SDA is high

}
return k;

// if counter i = 8 then
// MCU acknowledge
// returns contents of k

}
void STartUpDelay() {
Delay_ms(20);
}
void DisplayMeasurements(unsigned short rownumber) {
// Calculating temperature Tmp_res = D1 + D2 * SOt

if(SOt > D1) {


Tmp_res = SOt * D2 - D1;
}
else {
Tmp_res = D1 - SOt * D2;
}

// if temperature is positive
// calculate temperature
// else (if temperature is negative)
// calculate temperature

// Calculating humidity Rh_res = C1 + C2 * SOrh + C3 * SOrh^2


temp = SOrh * SOrh * C3 / 100000;
// calculate humidity
Rh_res = SOrh * C2 / 100 - temp - C1;
// calculate humidity
// Temperature compensation RHtrue=(T-25)*(T1+T2*SOrh)+RHlin
temp = (T1 + (T2 * SOrh)) / 1000;
temp = ( (Tmp_res - 2500) * temp) / 100;
Rh_res = temp + Rh_res;
// Preparing temperature for LCD
Tmp[0] = Tmp_res / 10000 + 48;
// example:
10000 = 1, 1 + 48 = '1' - ASCII
Tmp[1] = Tmp_res % 10000 / 1000 + 48;
// example:
10000 = 2345, Tmp[6] = 2345 / 1000 = 2, 2 + 48 = '2' - ASCII
Tmp[2] = Tmp_res % 1000 / 100 + 48;
// example:
1000 = 345, Tmp[7] = 345 / 100 = 3, 3 + 48 = '3' - ASCII
Tmp[4] = Tmp_res % 100 / 10 + 48;
// example:
100 = 45, Tmp[9] = 45 / 10 = 4, 4 + 48 = '4' - ASCII

Tmp[5] = 12345 /
Tmp[6] = 12345 %
Tmp[7] = 12345 %
Tmp[9] = 12345 %

// Preparing humidity for LCD


Rh[0] = Rh_res % 10000 / 1000 + 48;
// example: Rh[6] = 12345 % 10
000 = 2345, Rh[6] = 2345 / 1000 = 2, 2 + 48 = '2' - ASCII
Rh[1] = Rh_res % 1000 / 100 + 48;
// example: Rh[7] = 12345 % 10
00 = 345, Rh[7] = 345 / 100 = 3, 3 + 48 = '3' - ASCII
Rh[3] = Rh_res % 100 / 10 + 48;
// example: Rh[9] = 12345 % 10
0 = 45, Rh[9] = 45 / 10 = 4, 4 + 48 = '4' - ASCII
// delete unnecessary digits (zeros)
if (Tmp[0] == '0')
Tmp[0] = ' ';
o Tmp[5]
if (Tmp[0] == ' ' && Tmp[1] == '0')
p[6] = '0' then
Tmp[1] = ' ';
o Tmp[6]
if (Rh[0]
Rh[0]
Tmp[5]
if (Rh[0]
6] = '0' then
Rh[1]
Tmp[6]

// if Tmp[5] = '0' then


// insert blank character t
// if Tmp[5] is blank and Tm
// insert blank character t

== '0')
= ' ';

// if Tmp[5] = '0' then


// insert blank character to

== ' ' && Rh[1] == '0')

// if Tmp[5] is blank and Tmp[

= ' ';

// Display temperature on LCD


Lcd_Out(rownumber, 4, Tmp);
e on first row, i column
// Display humidity on LCD
Lcd_Out(rownumber, 12, Rh);
n second row, i column
}

// insert blank character to

// display temperatur
// display humidity o

#include <Io.h>
short div_hz;
int count, dt_tmr1, res_tmr1 = 65535;
short duty_cycle;
void interrupt() {
Soft_PWM_Inter(&PORTD, pin0);
/*if(TMR1IF_bit) {
if(!RD5_bit) {
TMR1L = duty_cycle;
RD5_bit = 1;
}
else if(RD5_bit) {
TMR1L = duty_cycle;
RD5_bit = 0;
}
TMR1IF_bit = 0;
TMR1H
= 0xFE;
TMR1L
= 0x0A;
}*/
}
/*//5000 Hz
void InitTimer0() {
T1CON = 0x01;
TMR1IE_bit = 1;
TMR1IF_bit = 0;
TMR1H = 0xFE;
TMR1L = 0x0A;
}*/
/*// 100 ms
void InitTimer0(){
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xDC;
TMR1IE_bit
= 1;
}*/
unsigned int ADCBITS = 0b0000000000000000, ADCBITS_PERCENT, PWMBITS, i = 0;
char ADCSTRG[5], ADCSTRG_PERCENT[4], PWMSTR[4];
unsigned const long Hz = 2000;
/***************DISPLAYS THE ADC VALUE********************/
void LCD_ADC() {
//Leitura Analoga AN0
ADCBITS = ADC_Read(0);
ADCSTRG[0] = ((ADCBITS / 1000) + 48);
//milhar
ADCSTRG[1] = (((ADCBITS / 100) % 10) + 48); //centena
ADCSTRG[2] = (((ADCBITS / 10) % 10) + 48); //dezena
ADCSTRG[3] = ((ADCBITS % 10) + 48);
//unidade
Lcd_Out(1, 1, "AN0:");
Lcd_Chr(1, 6, ADCSTRG[0]);
Lcd_Chr(1, 7, ADCSTRG[1]);

Lcd_Chr(1, 8, ADCSTRG[2]);
Lcd_Chr(1, 9, ADCSTRG[3]);
//Conversao Analoga An0 para %
ADCBITS_PERCENT = (ADCBITS / 1.023);
ADCSTRG_PERCENT[1] = (((ADCBITS_PERCENT / 100) % 10) + 48); //centena
ADCSTRG_PERCENT[2] = (((ADCBITS_PERCENT / 10) % 10) + 48); //dezena
ADCSTRG_PERCENT[3] = ((ADCBITS_PERCENT % 10) + 48);
//unidade
Lcd_Chr(1, 11, ADCSTRG_PERCENT[0]);
Lcd_Chr(1, 12, ADCSTRG_PERCENT[1]);
Lcd_Chr(1, 13, ADCSTRG_PERCENT[2]);
Lcd_Chr_CP('.');
Lcd_Chr(1, 15, ADCSTRG_PERCENT[3]);
Lcd_Out(1, 16, "%");
PWMBITS = ADCBITS;
PWMSTR[0] = ((PWMBITS / 1000)
PWMSTR[1] = (((PWMBITS / 100)
PWMSTR[2] = (((PWMBITS / 10)
PWMSTR[3] = ((PWMBITS % 10)
Lcd_Out(2, 1, "CCP1:");
Lcd_Chr(2, 7, PWMSTR[0]);
Lcd_Chr(2, 8, PWMSTR[1]);
Lcd_Chr(2, 9, PWMSTR[2]);
Lcd_Chr(2, 10, PWMSTR[3]);

+
%
%
+

48);
//milhar
10) + 48); //centena
10) + 48); //dezena
48);
//unidade

T2CON = 0b00000101;
// /T2OUTPS3/T2OUTPS2/T2OUTPS1/T2OUTPS0/TMR2ON/T2
CKPS1/T2CKPS0 // 0bxxxxxx10 = 16 / 0bxxxxxx01 = 4
PR2
= 1023;
//PR2 = 1023 (Peridode 819,20 uS)
//PWM 1
CCP1IE_bit = 1;
CCP1CON= 0b10111100;
P1M0
CCPR1L = PWMBITS >> 2;
CCP1CON.B4 = PWMBITS;
CCP1CON.B5 = PWMBITS >> 1;
//PWM 2
CCP2IE_bit
CCP2CON =
CCPR2L =
CCP2CON.B4
CCP2CON.B5

= 1;
0b00111100;
PWMBITS >> 2;
= PWMBITS;
= PWMBITS >> 1;

//P1M1/P1M0/DC1B1/DC1B0/CCP1M3/CCP1M2/CCP1M1/CC
//Duty Cicle 10 bits

// / /DC2B1/DC2B0/CCP2M3/CCP2M2/CCP2M1/CCP2M0
//Duty Cicle 10 bits

//PWM 3
}
unsigned long error = 0;
char duty_change = 0;
void main() {
INTCON= 0b00000000; //Desarma uC
TRISA = 0b00000001;
ADCON0= 0b00000001; // / /CHS3/CHS2/CHS1/CHS0/GO-DONE/ADON
ADCON1= 0b00001110; // / /VCFG1/VCFG0/PCFG3/PCFG2/PCFG1/PCFG0
TRISB = 0b00000000;
TRISC = 0b00000000;
TRISD = 0b00000000;
INTCON= 0b11000000; //Arma uC
Reset_IO();
Lcd_Config();

//InitTimer0();
Soft_PWM_Init(100);
Soft_PWM_Start();
while(1) {
LCD_ADC();
duty_cycle = (100 * PWMBITS) / 1023;
Soft_PWM_set_duty(duty_cycle);
}
}
short i;
char chr_valor[4];
int valor = 1234;
chr_valor[0]
chr_valor[1]
chr_valor[2]
chr_valor[3]

=
=
=
=

(valor / 1000)
((valor / 100)
((valor / 10)
( valor % 10)

+ 48;
% 10) + 48;
% 10) + 48;
+ 48;

for(i = 0; i < 4; i++) {


WR_I2C(ID_DEV_24C02C, i, chr_valor[i]);
Delay_10ms();
Lcd_Chr(1, 1, byte_wr_i2c[2]);
}
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
#define
TC74_READ
0x9B
#define
TC74_WRITE
0x9A
///////////////////////////////////////////////////
void tc74_init() {
delay_ms(10);
I2CStart();
I2CSend(TC74_WRITE);
I2CSend(0X01);
I2CSend(0);
I2CStop();
}
//////////////////////////////////////////////////////////////
void tc74_write(unsigned char reg,unsigned char val) {
I2CStart();
I2CSend(TC74_WRITE);
I2CSend(reg);
I2CSend(val);
I2CStop();
}
//////////////////////////////////////////////////////////////
void tc74_read(unsigned char reg,unsigned char *value) {
I2CStart();
I2CSend(TC74_WRITE);
I2CSend(reg);
I2CRestart();
I2CSend(TC74_READ);
*value = I2CRead(); //ACK
I2CStop();
}
tc74_init();
tc74_write(0x9A, 0x00);
tc74_read(0x9B, 0x00);
??????????????????????

unsigned char b, i;
void I2CWait(){
while ((SSPCON2 & 0x1F) || (SSPSTAT & 0x04));
pending transfer */
}
void I2CStart(){
I2CWait();
SEN_bit = 1;
while(SEN_bit);
}
void I2CStop(){

// wait for any

PEN_bit = 1;
while(PEN_bit);
ically cleared by hardware
}

// Stop condition enabled


// Wait for stop condition to finish PEN automat

void I2CRestart(){
RSEN_bit = 1;
while(RSEN_bit);
}

// Repeated start enabled


// wait for condition to finish

void I2CAck(){
ACKDT_bit = 0;
ACKEN_bit = 1;
while(ACKEN_bit);
}

// Acknowledge data bit, 0 = ACK


// Ack data enabled
// wait for ack data to send on bus

void I2CNak(){
ACKDT_bit = 1;
ACKEN_bit = 1;
while(ACKEN_bit);
}

// Acknowledge data bit, 1 = NAK


// Ack data enabled
// wait for ack data to send on bus

void I2CSend(unsigned char dat){


SSPBUF = dat;
// Move data to SSPBUF
while(BF_bit);
// wait till complete data is sent from buffer
I2CWait();
// wait for any pending transfer
}
unsigned char I2CRead(void){
I2CWait();
// Reception works if tr
ansfer is initiated in read mode
RCEN_bit = 1;
// Enable data reception
while(!BF_bit);
// wait for buffer full
return SSPBUF;
// Read serial buffer and store in temp
register wait to check any pending transfer
}
void I2Cwrite(){
I2CStart();
I2CSend(0x9A);
I2CSend(0x00);
I2CSend(0x23);
I2CStop();
}
void I2Cred() {
I2CStart();
I2CSend(0x9A);
I2CSend(0x00);
I2CRestart();
I2CSend(0x9B);
b = I2CRead();
I2CAck();
I2CStop();
}

// 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
#define
#define
#define

SCL_SCK RC3
SDA_SDI RC4
HIGH_SPEED 400000
NORNAL_SPEED 100000

//400kHz
//100kHz

400kBps
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;
//PIE1 = 0b00000001;
//IPR1 = 0b00000000;
//PIR1 = 0b00000000;

//OSCFIP/CMIP/ /EEIP/BCLIP/HLVDIP/TMR3IP/CCP2IP
//PSPIF/ADIF/RCIF/TXIF/SSPIF/CCP1IF/TMR2IF/TMR1IE
//PSPIP/ADIP/RCIP/TXIP/SSPIP/CCP1IP/TMR2IP/TMR1IP
//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

EECON1 = 0b00000001;

//EEPGD/C

ita ciclo de escrita EEPROM


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

Das könnte Ihnen auch gefallen