Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
html
ns01.claro.net.br
ns02.claro.net.br
ns04.claro.net.br
ns03.claro.net.br
ns05.claro.net.br
(
(
(
(
(
200.169.122.145 )
200.169.120.130 )
200.169.120.67 )
200.212.192.47 )
200.169.117.222 ) ok clarobr
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;
}
}
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 low
define SDA as input
repeat 10 times
invert SCL
//
//
//
//
//
//
//
//
//
//
//
//
{
= 1;
= 0;
= 1;
SCL_SCK = 0;
// SCL low
}
}
// MCU ACK
void MCU_ACK() {
if(Select == 1) {
SDA_SDI_Direction = 0;
SDA_SDI = 0;
SCL_SCK = 1;
Delay_1us();
SCL_SCK = 0;
Delay_1us();
SDA_SDI_Direction = 1;
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
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) {
// if temperature is positive
Tmp_res = SOt * D2 - D1;
// calculate temperature
}
else {
// else (if temperature is negative)
Tmp_res = D1 - SOt * D2;
// 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 %
== '0')
= ' ';
= ' ';
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
}
// 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]
ADCSTRG[1]
ADCSTRG[2]
ADCSTRG[3]
Lcd_Out(1,
Lcd_Chr(1,
Lcd_Chr(1,
Lcd_Chr(1,
Lcd_Chr(1,
= ((ADCBITS / 1000)
= (((ADCBITS / 100)
= (((ADCBITS / 10)
= ((ADCBITS % 10)
1, "AN0:");
6, ADCSTRG[0]);
7, ADCSTRG[1]);
8, ADCSTRG[2]);
9, ADCSTRG[3]);
+
%
%
+
48);
//milhar
10) + 48); //centena
10) + 48); //dezena
48);
//unidade
+
%
%
+
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
}
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
=
=
=
=
(valor / 1000)
((valor / 100)
((valor / 10)
( valor % 10)
+ 48;
% 10) + 48;
% 10) + 48;
+ 48;
unsigned char b, i;
void I2CWait(){
while ((SSPCON2 & 0x1F) || (SSPSTAT & 0x04));
pending transfer */
}
void I2CStart(){
I2CWait();
SEN_bit = 1;
while(SEN_bit);
}
void I2CStop(){
PEN_bit = 1;
while(PEN_bit);
ically cleared by hardware
}
void I2CRestart(){
RSEN_bit = 1;
while(RSEN_bit);
}
void I2CAck(){
ACKDT_bit = 0;
ACKEN_bit = 1;
while(ACKEN_bit);
}
void I2CNak(){
ACKDT_bit = 1;
ACKEN_bit = 1;
while(ACKEN_bit);
}
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;
//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++;
}
//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
Delay_ms(1000);
goto Ler_Set_Temp
//Salta no inicio do metodo lendo a temperatura da EEPROM
}
//Erro ao salvar Set
}
}
} 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);
}