novo documento de texto

Download Novo Documento de Texto

If you can't read please download the document

Upload: jonatan-allan-oliveira-souza

Post on 01-Feb-2016

5 views

Category:

Documents


0 download

DESCRIPTION

zsdxfcssdfsdfsdfsdf23423423.esfsd f sdjifpjsdpf3

TRANSCRIPT

http://www.edaboard.com/thread284335.htmlns01.claro.net.br ( 200.169.122.145 )ns02.claro.net.br ( 200.169.120.130 )ns04.claro.net.br ( 200.169.120.67 )ns03.claro.net.br ( 200.212.192.47 )ns05.claro.net.br ( 200.169.117.222 ) ok clarobrhttp://pt.scribd.com/doc/199324519/Cortex-m-Serieshttp://www.mikroe.com/forum/viewtopic.php?t=17449https://www.youtube.com/watch?v=v1dLdfa-7Ywhttp://saeedsolutions.blogspot.com.br/2012/10/pic16f84a-pwm-code-proteus-simulation.html// Constants for calculating temperature and humidity// SHT1x / SHT7x V4 humidity conversion coefficients (12 bits)const unsigned int C1 = 205; // -2.0468const 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.1const unsigned short D2 = 1; // 0.01unsigned 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; // SCL low SDA_SDI = 1; // define SDA as input for (i = 1; i 2; //Duty Cicle 10 bits CCP2CON.B4 = PWMBITS; CCP2CON.B5 = PWMBITS >> 1;} 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] = (valor / 1000) + 48; chr_valor[1] = ((valor / 100) % 10) + 48; chr_valor[2] = ((valor / 10) % 10) + 48; chr_valor[3] = ( valor % 10) + 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_0x3F=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_CKSEL0=P&V_LOW=62&V_HIGH=D9&V_EXTENDED=FF&O_DEFAULT=Defaultshttp://www.jayconsystems.com/tutorial/atmerpt1/filho olhe para o ceu, as estrelas a brilharEm meio a escuridao pra nos confortarE quando andamos pela noite, veja essa luzO amor que ha em mim, nesta cano de ninarpapai no dormepapai no se canano me assusto se trovejapois estou com meu paipapai nao dormepapai nao se cananao me assusto se trovejapois estou no colo do papaiQuando olho para o ceu, ouo uma vozEm meu coracao jamais te deixareiPreciso entender, que onde quer que eu vaEstou em tuas maos no controle tu estaspapai no dormepapai no se canano me assusto se trovejapois estou com meu paipapai nao dormepapai nao se cananao me assusto se trovejapois 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)); // wait for any pending transfer */}void I2CStart(){I2CWait(); SEN_bit = 1; while(SEN_bit);}void I2CStop(){ PEN_bit = 1; // Stop condition enabled while(PEN_bit); // Wait for stop condition to finish PEN automatically cleared by hardware}void I2CRestart(){ RSEN_bit = 1; // Repeated start enabled while(RSEN_bit); // wait for condition to finish}void I2CAck(){ ACKDT_bit = 0; // Acknowledge data bit, 0 = ACK ACKEN_bit = 1; // Ack data enabled while(ACKEN_bit); // wait for ack data to send on bus}void I2CNak(){ ACKDT_bit = 1; // Acknowledge data bit, 1 = NAK ACKEN_bit = 1; // Ack data enabled while(ACKEN_bit); // 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 transfer 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 connectionssbit 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 100kBpsvoid I2CWait() { while ((SSPCON2 & 0x1F) || (SSPSTAT & 0x04)); /* wait for any pending transfer */}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 Master 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/TMR1ONTMR1H = 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--; } //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) + 48); //centena chr_sp_temp[1] = (((sp_temp / 10) % 10) + 48); //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--; } //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) check_passwd++; } Lcd_Out(2, 1, "Senha: "); chr_passwd[0] = (((check_passwd / 100) % 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; //Desabilita ciclo de escrita EEPROM EECON1 = 0b00000001; //EEPGD/CFGS/-/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 correta"); 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_CLEAR); WREN_bit = 0; //Desabilita ciclo de escrita EEPROM Lcd_Out(3, 1, "Set Salvo!"); Delay_ms(1000); goto Ler_Set_Temp; //Salta no inicio do metodo lendo a temperatura da EEPROM } //Erro ao salvar Setpoint Temperatura na EEPROM else if(fail) { Lcd_Cmd(_LCD_CLEAR); WREN_bit = 0; //Desabilita ciclo de escrita EEPROM EEIF_bit = 0; //Limpa flag da EEPROM INTCON = 0b11000000; //Carrega estado previo salvo de INTCON Lcd_Out(3, 1, "Erro ao Salvar!"); Delay_ms(1000); } sp_temp_flag = 0; } //Senha errada else { EEIF_bit = 0; Lcd_Out(3, 5, "Senha errada"); 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); }