Reputation: 1
I would like to know why the simulation is going wrong in the Proteus Professional. Well, on this circuit and code, I tried to make a Temperature sensor with fans following the following conditions:
I'm using a PIC18F4520
This is the code and the error in Proteus:
// PIC18F4520 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1H
#pragma config OSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
#pragma config BORV = 3 // Brown Out Reset Voltage bits (Minimum setting)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include"LCD4b_EXSTO.h"
#include <stdio.h>
#define _XTAL_FREQ 8000000
#define FAN1 PORTCbits.RC0
#define FAN2 PORTCbits.RC1
#define RES PORTCbits.RC2
//botao
#define B1 PORTBbits.RB0
unsigned int VdigADC;
float TENSAO, graus, porcen;
void config_IO()
{
TRISC = 0X00;
PORTC = 0XFF;
}
void config_ADC()
{// PARA O AN0
ADCON0 = 0X01; // Sele??o dos canais anal?gicos; Estado da convers?o e Habilita??o do Conversor A/D PADRAO
ADCON1 = 0X0E; // Tens?o de refer?ncia; Sele??o de entrada anal?gica | PORTA AN3 -> 1011
ADCON2 = 0X87; // Alinhamento dos Bits (ADRES); Tempo de aquisi??o; Fonte de Clock para o converesor A/D PADRAO
}
void config_FOSC()
{
OSCCON = 0X00;
OSCTUNE = 0X00;
}
void equacao(){
TENSAO = VdigADC * 0.004887585532746823069403714565;
graus = TENSAO / 0.01190476190476190476190476190476;
porcen = (graus * 100) / 420;
}
void conv_AN0()
{
__delay_ms(200);
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
VdigADC = ADRESH;
VdigADC = (VdigADC << 8) + ADRESL;
equacao();
}
void porc(){
conv_AN0();
if(porcen<25)
{
RES=0;
FAN1=1;
FAN2=1;
}
else if(porcen>25 && porcen<=50)
{
RES=0;
FAN1=0;
FAN2=1;
}
else if(porcen>50 && porcen<=75)
{
RES=0;
FAN1 =0;
FAN2=0;
}
else if(porcen>75)
{
RES=1;
FAN1 =0;
FAN2=0;
}
}
void lcd(){//BLOCO DO LCD
char temperatura[16];
char percentual[16];
char fan1[16];
char fan2[16];
char res[16];
lcd_init();
lcd_clear();
__delay_ms(100);
while(B1 == 1){
lcd_clear();
porc();
lcd_write(1,1,"FAN 1:");//linha 1 fan1
sprintf(fan1, "%d",FAN1);
lcd_write(1,7,fan1);
lcd_write(1,9,"FAN 2:");//linha 1 fan2
sprintf(fan2, "%d",FAN2);
lcd_write(1,16,fan2);
lcd_write(2,1,"RES:");//linha 2 res
sprintf(res, "%d ",RES);
lcd_write(2,6,res);
__delay_ms(100);
}
lcd_clear();
__delay_ms(100);
while(B1==0)// exibe temperatura e porcentagem
{
lcd_clear();
__delay_ms(100);
porc();
//linha 1
lcd_write(1,1,"Temp:");
sprintf(temperatura, "%.1f%cC ", graus, 0XDF);
lcd_write(1,9,temperatura);
//linha 2
lcd_write(2,1,"Percent:");
sprintf(percentual, "%.1f%c ", porcen, 0X25);
lcd_write(2,10,percentual);
__delay_ms(100);
}
}
void main()
{
config_FOSC();
config_ADC();
config_IO();
lcd();
}
I tried looking for the error on the internet, but I couldn't find anything that really helped me.
Upvotes: 0
Views: 71