Ir ao conteúdo
  • Cadastre-se

Projeto Aquario automatizado/16f877a


tcc

Posts recomendados

gostaria de saber se alguém tem algum material sobre programação em C para pics, uso MIKROC pro pic. neste projeto estou usando uns display lcd e quero fazer uma interação do operador com ele!...Já consegui alguma coisa porém meu programa esta meio pobre e com algumas limitações. abaixo segue ele....

#define iluminacao portb.f5
#define FOOD portb.f6
#define luz portb.f3
#define CANI portb.f4
// pinos do LCD
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

// variaveis:


char *Aq=" AQUARIO";
char *Au=" AUTOMATIZADO";


void main() {
// configuração das portas
trisb.f3=0;
trisb.f5=1;
trisb.f6=1;
trisd=0b00000000;
adcon1=0b00000000;
CMCON=0xff;
trisc=0b00000000;
//inicialização do LCD

Lcd_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);

// inicialização dos bits
luz=0;
FOOD=0;

//laço infinito

while(1){

LCD_Out(1,1, Aq);
LCD_Out(2,1, Au);

if (iluminacao==1) { luz=1; lcd_out(3,-3, "LUZ ON"); }

else{
LCD_Out(3,-3, "LUZ OFF");
delay_ms(100);
luz=0;
}
if (FOOD==1){ lcd_out(4,-3, "FOOD ON"); portc.f3=1;delay_ms(1000);portc.f3=0; portc.f2=1;delay_ms(1000);portc.f2=0; portc.f4=1;delay_ms(1000);portc.f4=0; portc.f1=1;delay_ms(3000);portc.f1=0; }
else {
lcd_out(4,-3, "FOOD OFF ");
}
if (CANI==1) { portc.f5=1; lcd_out(3,5, "CANI ON"); }
else{
lcd_out(3,5, "CANI OFF"); portc.f5=0;
}

}

}

ele esta meio limitado pelo fato de eu não conseguir realizar apenas uma operação de cada vez, no caso da alimentação é usado um motor , então são contados alguns segundos , impedindo que eu acenda a luz ou ligue o CANI(filtro).

se quiserem ver o projeto no proteus e so falarem que eu posto.

aceito todos os tipos de dicas e criticas, seu novato na programação e preciso da ajuda de vocês.

meu objetivo e aprender e não fazer vocês fazerem o programa para mim!

abraço!

Link para o comentário
Compartilhar em outros sites

Amigo,seguinte pode tentar copiar umas coisas do meu codigo de automçao residencial

#include <16f873a.h>

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Clock <=4Mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection

#use delay(clock=4000000)


#include <flex_lcd.c>

#define botao_incremento PIN_a2
#define botao_decremento PIN_a3
int16 q=0; //Variável que incrementa a cada 0.5s dentro da interupção do timer1.
int s=0; //Variável dos segundos, incrementa na metade de q.
int m=0; //Variável dos minutos. 0 a 59
int h=12;
int hlq,minlq;
int hdq,mindq;
int mq=0,mv;
int a=0,b=0,c=0,d=0,e=0;
int8 modo;
int lamp_q,lamp_c,lamp_cor;
int tempo;
float valor;
int temperatura,temp;
int ativo=1;
#int_TIMER1
void trata_timer_1(void)
{
q++;
set_timer1 (3036);

}
#int_ccp1
void trata_ccp_1()
{
if(modo>0){
modo--;
}
if (modo ==255)
{
modo = 0;
}
}
#int_ccp2
void trata_ccp_2()
{
modo++;
if (modo >9)
{
modo = 0;
}
}
void hora(){

set_adc_channel(0);
delay_us(20);
valor = read_adc ();
temperatura = 5 * valor * 100/1024;
s=q/2; //A variável Q incrementa a 2Hz, então os segundos
//devem ser a metade.
if (s==60) //Se for igual a 60, reset em Q e S. M incrementa.
{
q=0;
s=0;
m++;
}

if (m>59)
{
m=0;
h++;
}

if (h>23) //Se H(horas) for maior q 23, reset. DIA DA SEMANA
{ //e DIA DO MÊS incrementam.

h=0;
}

// printf (lcd_putc, "\f Domotica ");


// printf (lcd_putc, "\n%02u:%02u:%02u %02u%cc"h, m, s,temperatura,0xDF );
// delay_ms(100);
}





void main()
{

lcd_init();
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_8);
set_timer1 (3036);
enable_interrupts(INT_TIMER1);
setup_ccp1(CCP_CAPTURE_RE);
enable_interrupts (int_ccp1);
setup_ccp2(CCP_CAPTURE_RE);
enable_interrupts (int_ccp2);
enable_interrupts(global);
#priority timer1,ccp2,ccp1
while(1){

switch(modo){
case 0:{
hora();
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
output_high(pin_c0);
a=1;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);

output_low(pin_c0);
a=0;
}
printf (lcd_putc, "\f Ilum.Quarto");
if(a==1){
printf (lcd_putc, "\n luz acesa");
delay_ms(100);
}

if(a==0){
printf (lcd_putc, "\n luz apagada");
delay_ms(100);
}

if((temperatura>=temp)&(mv==1)){
e=1;
output_high(pin_c3);
}
if((temperatura<temp)&(mv==1)){
e=0;
output_low(pin_c3);
}
}

break;

case 1:{
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
mq++;
if(mq>1){
mq=1;
}
}



if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
mq--;
if(mq==255){
mq=0;
}
}
printf (lcd_putc, "\f Ilum.Quarto");
if(mq==1){
printf (lcd_putc, "\n Automatica");
delay_ms(100);
}

if(mq==0){
printf (lcd_putc, "\n Manual");
delay_ms(100);
}

}
break;

case 2:{

switch(mq){

case 1:{

while (modo == 2){
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
hlq++;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
hlq--;
}

printf (lcd_putc, "\fHORA ligar lamp\n%02u:%02u",hlq,minlq);
delay_ms (100);
}

while (modo == 3)
{
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
minlq++;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
minlq--;
}

printf (lcd_putc, "\fHORA ligar lamp\n%02u:%02u",hlq,minlq);
delay_ms (100);
}

while (modo == 4){
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
hdq++;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
hdq--;
}

printf (lcd_putc, "\fHora desl. lamp\n%02u:%02u",hdq,mindq);
delay_ms (100);
}

while (modo == 5)
{
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
mindq++;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
mindq--;
}

printf (lcd_putc, "\fhora desl. lamp\n%02u:%02u",hdq,mindq);
delay_ms (100);
}
modo=3;
}
}
}





break;

case 3:{
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
mv++;
if(mv>1){
mv=1;
}
}



if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
mv--;
if(mv==255){
mv=0;
}
}
printf (lcd_putc, "\f Ventilador");
if(mv==1){
printf (lcd_putc, "\n Automatico");
delay_ms(100);
}

if(mv==0){
printf (lcd_putc, "\n Manual");
delay_ms(100);
}

}
break;
case 4:{
switch(mv){

case 0:{
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
output_high(pin_c3);
e=1;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);

output_low(pin_c3);
e=0;
}
printf (lcd_putc, "\f Ventilador");
if(e==1){
printf (lcd_putc, "\n ligado");
delay_ms(100);
}

if(e==0){
printf (lcd_putc, "\n desligado");
delay_ms(100);
}
}


break;

case 1:{

while (modo ==4){
if (!input(BOTAO_INCREMENTO))
{
delay_ms (75);
temp++;
}

if (!input(BOTAO_DECREMENTO))
{
delay_ms (75);
temp--;
}

if(e==1){
printf (lcd_putc, "\fTemp.acionar\n%02u%cc ligado",temp,0xDF );
delay_ms(100);
}

if(e==0){
printf (lcd_putc, "\fTemp.acionar\n%02u%cc desligado.",temp,0xDF );



delay_ms (100);
}




}
}
}





break;

}
}
}

}


Link para o comentário
Compartilhar em outros sites

então jorge pelo que percebi o jeito é usar varios void(), mas como sou iniciante nao consegui ainda jogar isso em meu código, meu objetivo é ter um lcd que o operador possa interagir escolhendo cada função de uma vez, e poder ver seus status também (ligado)(desligado), neste meu código disse que ficou precário pelo fato de aparecer tudo de uma vez no display e apenas mostra se ta ligado ou nao, e também so executa uma função de cada vez "/

poderia me ajudar a melhorar este meu código?

agradeço pela colaboração

abraço.

Link para o comentário
Compartilhar em outros sites

Puxão de orelha que vai para os dois, quando forem escrever um código em C qualquer

que seja o compilador, lembrem-se de colocar os prototipos de cada função no começo do programa, isso evita bagunça e erros de compilação porque uma função precisa da outra

mas a mesma ainda não foi definida, exemplo:



//protitipo da funcao

unsigned int Soma (unsigned int a, unsigned int ;

//aqui fazemos a funcao
unsigned int Soma (unsigned int a, unsigned int
{

.....seu codigo aqui

}

//e por fim a sua chamada no void main como exemplo

void main ()
{
...
c = Soma (5,6);
....
}


Comecem organizados agora no aprendizado e verão como fica muito mais fácil manipular o código e encontrar possiveis erros ;D

Abs.

Link para o comentário
Compartilhar em outros sites

O amigo analisando teu projeto,primeiro use interrupçao do timer pra gerar o tempo,assim teu programa nao fica parado enquanto executa o delay.Outra coisa coloque um botao que incremente uma variavel e faça um switch case para selecionar os menus ,deu pra entender? se olhar no meu ira ter a ideia que estou falando ,abraços.....

Link para o comentário
Compartilhar em outros sites

então jorge, fiquei 2 horas aqui tentando mas não obtive sucesso ,apenas piorei meu projeto, pra falar a verdade não sei usar esse timer que você falou, então parti para a função switch/case , mas também não ficou bom. fiz um botao de incremento e um de decremento porém do resto não consegui.

se puder me ajudar fico grato, não pense que quero jogar o projeto nas custas de vocês, muito pelo contrario, eu quero muito aprender isso, mas como sou iniciante ainda tenho muitas duvidas.

abraço a todos

Link para o comentário
Compartilhar em outros sites

então jorge eu ainda nao consegui..."/

meu codigo ta assim:

while(1){
if (botao_incremento==1){
x++; //coloquei uma variavel int x;//
if (x==4){
x=0;}
switch(x){
case 0:{
lcd_out(1,2,"iluminacao");
break;
}
case 1:{
lcd_out(1,2,"Canister");
break;
}
case 2:{
lcd_out(1,2,"Temperatura");
break;
}
case 3:{
lcd_out(1,2,"alimentacao");
break;
}
}
}
}

nao funcionou , o lcd fica piscando... add um botao no portb.f7(botao_incremento).

se puder ajudar agradeço

abrço

Link para o comentário
Compartilhar em outros sites

Ae felipao desculpe mais nao entendi nada do que quis dizer kkkkkkkkkkkkkkkkk.

O felipe falou para vocês colocarem o protótipo de cada função no cabeçalho do arquivo, junto a declaração das variáveis. Que nem no exemplo dele.

Outra coisa, é SEMPRE importante fazer uma indentação no código de forma correta.

Link para o comentário
Compartilhar em outros sites

Ola meu amigo Jorge... Desculpe a demora para responder mas é que precisei viajar, porém dei uma boa adiantada no meu projeto, e já esta ficando bem legal!

de uma olhada...

//Projeto Aquario Automatizado//


#define iluminacao portb.f5
#define FOOD portb.f6
#define luz portb.f3

#define botao_desliga portb.f4
#define botao_incremento portb.f7
#define botao_liga portb.f2
// pinos do LCD
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

// variaveis:

char *aq=" AQUARIO";
char *au=" AUTOMATIZADO";

int menu,lamp1,filtro,alimentador,contagem;
int tt;
char tt_txt[7];
int tt1=15,tt2=25;

void main() {

// configuração das portas
trisb.f3=0;
trisb.f5=1;
trisb.f6=1;
trisd=0b00000000;
adcon1=0b000000000000;
trisa.f0=1;
trisa.f3=0;
CMCON=0xff;
trisc=0b00000000;

//inicialização do LCD

Lcd_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);

// inicialização dos bits
luz=0;
FOOD=0;
botao_incremento=0;
//laço infinito

while(1){
if(botao_incremento==1){
menu ++; }
if (menu==5){
menu=0;}


switch(menu){
case 0:{
tt=ADC_Read(0);
IntTostr(tt,tt_txt);
lcd_out(4,4,tt_txt);

lcd_out(1,1,aq);
lcd_out(2,1,au);
delay_ms(300);
break;}

//CASO 1 CUIDA DA PARTE DA ILUMINACAO DO AQUARIO//
case 1:{
LCD_Cmd(_LCD_CLEAR);
lcd_out(2,4,"ILUMINACAO");
delay_ms(200);


if(botao_liga==1){
lamp1++;
}

if(lamp1==1) {
luz=1;
lcd_out(3,0,"LUZ ACESA");
delay_ms(500);

}
if(botao_desliga==1) {
lamp1--;
}
if(lamp1==0){
lcd_out(3,0,"LUZ APAGADA");
delay_ms(500);
luz=0;

}
break;
}
case 2:{
LCD_Cmd(_LCD_CLEAR);
lcd_out(2,6,"FILTRO");
delay_ms(500);

if (botao_liga==1){
filtro++;
}
if(filtro==1){
portc.f5=1;
lcd_out(3,-1,"FILTRO LIGADO");
delay_ms(500);
}
if (botao_desliga==1){
filtro--;
}
if (filtro==0){
portc.f5=0;
lcd_out(3,-3,"FILTRO DESLIGADO");
delay_ms(500);
}

break;
}
case 3: {
LCD_Cmd(_LCD_CLEAR);
lcd_out(2,4,"ALIMENTACAO");
delay_ms(500);

if(botao_liga==1){
alimentador++;
contagem++;
}

if (contagem==1){

lcd_out(3,4,"1");
delay_ms(1000);
}
if (contagem==2){
lcd_out(3,4,"2");
delay_ms(1000);
}
if (contagem==3){
lcd_out(3,4,"3");
delay_ms(1000);
}
if (contagem>=4){

lcd_out(3,-2,"lim");
delay_ms(600);
alimentador=0;
}
if(alimentador==1){

portc.f3=1;
delay_ms(1000);
portc.f3=0;

portc.f2=1;
delay_ms(1000);
portc.f2=0;

portc.f4=1;
delay_ms(1000);
portc.f4=0;

portc.f1=1;
delay_ms(3000);
portc.f1=0;
alimentador=0;
lcd_out(3,1,"CONCLUIDA");
delay_ms(2500);
}

break;
}
case 4:{
LCD_Cmd(_LCD_CLEAR);

lcd_out(2,4,"AUTOMATICO");
delay_ms(500);
LCD_Cmd(_LCD_CLEAR);
break;
}
}
}

}

Meu problemas são:

*coloquei um lm35 ligado a port ra0 do pic(16f877a), porém depois que fiz isso eu fiquei limitado a escrever meu programa, principalmente quando quero escrever algo no display, se for algo acima de 5 letras o pic entra em conflito e fica acionando varias saídas... e se eu tirar o lm35 posso escrever normalmente...

*Uso o lm35 para medir a temperatura da água do aquário, na frente da leitura gostaria de escrever algo como ºC , mas ai que entra no mesmo conflito anterior, fica acionando varias portas do pic...

*Quando o aquario chegar numa certa temp. gostaria de acionar uma resistencia para esquentar a agua, mas nao consegui fazer isso.

conto com ajuda de vocês , se precisarem no projeto no proteus eu passo.

Abraço.

Link para o comentário
Compartilhar em outros sites

Eu vou fazer uma automatizaçao do jeito que deseja ,te passo o codigo ,e você estuda ele cara pra aprender,nao é so copiar e pronto.Vai de você então.... mais a noite posto o codigo. abraços.

Mas você não precisa fazer isso pra mim amigo... meu intuito aqui com certeza e aprender.... porém to com algumas dificuldades que não consigo resolver, mas fora esses problemas tive muitos outros, mas com persistência consegui resolver!

sim eu estudarei o código, mas acho que seria mais fácil se você tentasse me ajudar nesse meu código, dando algumas dicas e tentando me ajudar com os erros.

mesmo assim obrigado por estar me ajudando e o que você resolver ta bom!

abraço.

Link para o comentário
Compartilhar em outros sites

Seria interessante ter na tela principal todas informaçoes ,tipo:

Se no menu configurou lampada como manual, então na tela principal poderá via botao ligar e desligar,se configurou automatico então na tela principal marca como tal ,e ela acendera quando atingir o horario.A temperatura tbem ,junto com hora e o resto do menu poderiam estar na tela principal.

então no case 0 você colocaria todas opções configuradas do menu entendeu?

Link para o comentário
Compartilhar em outros sites

  • mês depois...
  • mês depois...
gostaria de saber se alguém tem algum material sobre programação em C para pics, uso MIKROC pro pic. neste projeto estou usando uns display lcd e quero fazer uma interação do operador com ele!...Já consegui alguma coisa porém meu programa esta meio pobre e com algumas limitações. abaixo segue ele....

#define iluminacao portb.f5
#define FOOD portb.f6
#define luz portb.f3
#define CANI portb.f4
// pinos do LCD
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

// variaveis:


char *Aq=" AQUARIO";
char *Au=" AUTOMATIZADO";


void main() {
// configuração das portas
trisb.f3=0;
trisb.f5=1;
trisb.f6=1;
trisd=0b00000000;
adcon1=0b00000000;
CMCON=0xff;
trisc=0b00000000;
//inicialização do LCD

Lcd_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);

// inicialização dos bits
luz=0;
FOOD=0;

//laço infinito

while(1){

LCD_Out(1,1, Aq);
LCD_Out(2,1, Au);

if (iluminacao==1) { luz=1; lcd_out(3,-3, "LUZ ON"); }

else{
LCD_Out(3,-3, "LUZ OFF");
delay_ms(100);
luz=0;
}
if (FOOD==1){ lcd_out(4,-3, "FOOD ON"); portc.f3=1;delay_ms(1000);portc.f3=0; portc.f2=1;delay_ms(1000);portc.f2=0; portc.f4=1;delay_ms(1000);portc.f4=0; portc.f1=1;delay_ms(3000);portc.f1=0; }
else {
lcd_out(4,-3, "FOOD OFF ");
}
if (CANI==1) { portc.f5=1; lcd_out(3,5, "CANI ON"); }
else{
lcd_out(3,5, "CANI OFF"); portc.f5=0;
}

}

}

ele esta meio limitado pelo fato de eu não conseguir realizar apenas uma operação de cada vez, no caso da alimentação é usado um motor , então são contados alguns segundos , impedindo que eu acenda a luz ou ligue o CANI(filtro).

se quiserem ver o projeto no proteus e so falarem que eu posto.

aceito todos os tipos de dicas e criticas, seu novato na programação e preciso da ajuda de vocês.

meu objetivo e aprender e não fazer vocês fazerem o programa para mim!

abraço!

ver se esse serve


// LCD module connections
//ENVIANDO EM 11 DE JANEIRO DE 2012 POR [email protected]
/// ACESSE O MEU SITE LA TEM MAIS albertoice.webcindario.com
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_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_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
sbit Gate_Enable at RC1_bit;
unsigned long RPM_Value;
char message3[] = "tensão=";
char message4[] = "Corrente=";
char message5[] = "Freq= Hz";
unsigned int ADC_Value, DisplayVolt, DisplayCurr, AdjustVolt;
char *volt = "00.0";
char *amp = "0.000";
//unsigned int Num;
char *freq = "00000.00";
long counter, Num, lowfreq;
unsigned short CountDone, upscale, prescaler;

void Display_Freq(long freq2write) {

freq[0] = (freq2write/10000000) + 48; // Extract tens digit
freq[1] = (freq2write/1000000)%10 + 48; // Extract ones digit
freq[2] = (freq2write/100000)%10 + 48;
freq[3] = (freq2write/10000)%10 + 48;
freq[4] = (freq2write/1000)%10 + 48;
freq[6] = (freq2write/100)%10 + 48;
freq[7] = (freq2write/10)%10 + 48;
// Display Frequency on LCD
Lcd_Out(2, 6, freq);
}

long count_pulse(){
long ff = 0;
Gate_Enable = 0;
CountDone = 0;
Num = 0;
TMR1L = 0xDC; //TMR1 start time = 3036 for 100 ms
TMR1H = 0x0B;
TMR0 = 0;
T1CON.TMR1ON = 1;
do {

}while(!CountDone);
Gate_Enable = 1;
T1CON.TMR1ON = 0; // Disable Timer1
ff = 256*Num + TMR0;
ff = ff*10*prescaler;
return ff;

}

// Interrupt service routine
void interrupt() {
if(INTCON.T0IF){
Num ++; // Interrupt causes Num to be incremented by 1
INTCON.T0IF = 0; // Bit T0IF is cleared so that the interrupt could reoccur
}
if (PIR1.TMR1IF){ //Let me use this even if no other interrupts are enabled
CountDone = 1;
PIR1.TMR1IF = 0; //reset timer1 flag
}
}






////ALTERACAO

sbit SelectButton at Rd7_bit;
long leitura_ad = 0, aux = 0;
char texto[5] = "00.0";
char valor[5] = "00.0";
long setpoint;
char teste = 1;
unsigned int select, update_select;

void debounce_delay(void){
Delay_ms(333);
}

void atualiza_lcd(){ // funçao atualiza lcd
Lcd_Init();

delay_ms(20);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);


}

void escreve_eeprom() {
EEPROM_Write (0,setpoint);
EEPROM_Write (1,setpoint>>8); // quebra var.teste de 16bit em dois de 8

delay_ms(40);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_out(1,4, "SUCESSSO");
Lcd_out(2,1, "AJUSTE GRAVADO");
delay_ms(800);
atualiza_lcd();

}
// Define Messages


void main() {
trisa.ra0 = 1;
trisa.ra1= 1; //configrada como entrada
trisa.ra2= 1; //configrada como entrada
ADCON1 = 0x82; // configure VDD as Vref, and analog channels

INTCON = 0;
PORTC = 0;
TRISB = 3; //'configura todos os pinos do portd como saída
TRISD = 3; //'configura todos os pinos do portd como saída
TRISE = 0; //'configura todos os pinos do porte como saída
TRISC = 0; //'configura todos os pinos do portd como saída

//'configura AN0,AN1,AN3 COMO analógico e os demais pinos como digital
Gate_Enable = 1;
// TMR1 settings
T1CON.TMR1CS = 0; // Fosc / 4
T1CON.T1CKPS1 = 1; // Setting prescale value to 1:8
T1CON.T1CKPS0 = 1;
PIE1.TMR1IE = 1;
INTCON.PEIE = 1;
INTCON.T0IE = 1;
INTCON.GIE = 1;
Lcd_Init();

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,13, texto);
Lcd_Out(2,13, valor);
atualiza_lcd();

setpoint = eeprom_Read(1);setpoint<<=8;
setpoint |= eeprom_Read(0);

select = 0;
update_select = 1;

do {
if(!SelectButton){
debounce_delay();
update_select = 1;
switch (select) {
case 0 : select=1;
break;
case 1 : select=2;
break;
case 2: select=3;
break;
case 3: select=4;
break;
case 4: select=0;
break;
} //case end
}
if(select == 0){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);


update_select=0;
}
////////////////////********/////
leitura_ad = adc_read(0);
aux = leitura_ad;

leitura_ad = leitura_ad*5000/1023;
texto[0] = (leitura_AD%1000)/100 + 48;
texto[1] = (((leitura_AD%1000)%100)/10) + 48;
texto[2] = '.';
texto[3] = (((leitura_AD%1000)%100)%10) + 48;
Lcd_Out(1,13, texto);

if (Button(&PORTD, 0, 20 ,0)){ //verifica tecla1.
setpoint++;
}

if (Button(&PORTD, 1, 20, 0)){ //verifica se a tecla2.
setpoint--;
}
if (PORTd.Rd5 == 0){ //se portb.rb0 estiver em nivel baixo chama funçao
escreve_eeprom(); //chama a funçao escreve na eeprom
}
if (PORTd.Rd4 == 0 && teste ==1 ){
portc.rc7 = ~portc.rc7;
teste = 0; }
delay_ms(20);
if (PORTd.rd4 == 1 && teste == 0 ){
teste = 1;
delay_ms(20);
}
if(portc.rc7==1){
Lcd_out(2,10, "TL");
} else Lcd_out(2,10, "TD");

valor[0] = (setpoint%100)/10 + 48;
valor[1] = ((setpoint%100)%10) + 48;
valor[2] = '.';
valor[3] = '0';
Lcd_out(2,13, valor);
Lcd_Out(1,1,"TEMPERATURA");
Lcd_Out(2,1,"AJUSTE");
if (aux/2 <= setpoint){
portc.rc0 = 0;
}
else portc.rc0 = 1;
}//FIM DO MENU 0
if(select == 1){ // Diode Tester
if(update_select){

Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"VOLTIMETRO");

update_select=0;
}
// Read Voltage

ADC_Value = ADC_Read(1);
DisplayVolt = ADC_Value * 2;
AdjustVolt = DisplayCurr/1000;
AdjustVolt = 29*AdjustVolt ; // 29 corresponds to 0.286 Ohm
DisplayVolt = DisplayVolt - AdjustVolt;
volt[0] = DisplayVolt/1000 + 48;
volt[1] = (DisplayVolt/100)%10 + 48;
volt[3] = (DisplayVolt/10)%10 + 48;
Lcd_Out(2,9,volt);
Lcd_Out(2,1,Message3);
Lcd_Chr(2,13,'V');
///AQUI VAI OS TEXTO

} // End if (detail_select)

if(select == 2){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"AMPERIMETRO");

update_select=0;
}
// Read Current
ADC_Value = ADC_Read(2);
DisplayCurr = ADC_Value * 17;
amp[0] = DisplayCurr/10000 + 48;
amp[2] = (DisplayCurr/1000)%10 + 48;
amp[3] = (DisplayCurr/100)%10 + 48;
amp[4] = (DisplayCurr/10)%10 + 48;
Lcd_Out(2,10,amp);
Lcd_Chr(2,15,'A');

///AQUI VAI OS TEXTO
} // End if (detail_select)
if(select == 3){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"FREQUENCIMETRO");

update_select=0;
}
// Calculate Frequency
// First begin with prescaler 1:64
OPTION_REG = 0b00110101; // Prescaler (1:64), TOCS =1
prescaler = 64;

Counter = count_pulse();

if (Counter > 99990) {
Display_Freq(Counter);
Lcd_Chr(2,14,'K');
//lowfreq = Counter*1000;
//Lcd_Out(2,1,message5);
//Display_Freq(lowfreq);
}
if (Counter <= 99990) {
OPTION_REG = 0b00111000; // Prescaler (1:1), TOCS =1
prescaler = 1;
Counter = count_pulse();
Counter = 1000*Counter;
Display_Freq(Counter);
Lcd_Chr(2,14,'H');
Lcd_Chr(2,15,'z');
}
Delay_ms(3);
// Ends Frequency display
///AQUI VAI OS TEXTO
} ///FIM DO MENU
if(select == 4){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"CONTA GIRO");

update_select=0;
}


///AQUI VAI OS TEXTO
} ///FIM DO MENU
//iluminacao no lcd liga e desliga
if (PORTd.Rd4 == 0 && teste ==1 ){
portc.rc7 = ~portc.rc7;
teste = 0; }
delay_ms(20);
if (PORTd.rd4 == 1 && teste == 0 ){
teste = 1;
delay_ms(20);
}
if(portc.rc7==1){
;
} else ;


} while(1);
}

Link para o comentário
Compartilhar em outros sites

huum acho que entendi, bom Jorge estou indo pra aula agora e acho que vou trabalhar em nisso hj...

amanha falo se deu certo ou nao...

abraço..

tai amigao um completo 11/01/2012


sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_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_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
sbit Gate_Enable at RC1_bit;
unsigned long RPM_Value;
char message3[] = "tensão=";
char message4[] = "Corrente=";
char message5[] = "Freq= Hz";
unsigned int ADC_Value, DisplayVolt, DisplayCurr, AdjustVolt;
char *volt = "00.0";
char *amp = "0.000";
//unsigned int Num;
char *freq = "00000.00";
long counter, Num, lowfreq;
unsigned short CountDone, upscale, prescaler;

void Display_Freq(long freq2write) {

freq[0] = (freq2write/10000000) + 48; // Extract tens digit
freq[1] = (freq2write/1000000)%10 + 48; // Extract ones digit
freq[2] = (freq2write/100000)%10 + 48;
freq[3] = (freq2write/10000)%10 + 48;
freq[4] = (freq2write/1000)%10 + 48;
freq[6] = (freq2write/100)%10 + 48;
freq[7] = (freq2write/10)%10 + 48;
// Display Frequency on LCD
Lcd_Out(2, 6, freq);
}

long count_pulse(){
long ff = 0;
Gate_Enable = 0;
CountDone = 0;
Num = 0;
TMR1L = 0xDC; //TMR1 start time = 3036 for 100 ms
TMR1H = 0x0B;
TMR0 = 0;
T1CON.TMR1ON = 1;
do {

}while(!CountDone);
Gate_Enable = 1;
T1CON.TMR1ON = 0; // Disable Timer1
ff = 256*Num + TMR0;
ff = ff*10*prescaler;
return ff;

}

// Interrupt service routine
void interrupt() {
if(INTCON.T0IF){
Num ++; // Interrupt causes Num to be incremented by 1
INTCON.T0IF = 0; // Bit T0IF is cleared so that the interrupt could reoccur
}
if (PIR1.TMR1IF){ //Let me use this even if no other interrupts are enabled
CountDone = 1;
PIR1.TMR1IF = 0; //reset timer1 flag
}
}






////ALTERACAO

sbit SelectButton at Rd7_bit;
long leitura_ad = 0, aux = 0;
char texto[5] = "00.0";
char valor[5] = "00.0";
long setpoint;
char teste = 1;
unsigned int select, update_select;

void debounce_delay(void){
Delay_ms(333);
}

void atualiza_lcd(){ // funçao atualiza lcd
Lcd_Init();

delay_ms(20);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);


}

void escreve_eeprom() {
EEPROM_Write (0,setpoint);
EEPROM_Write (1,setpoint>>8); // quebra var.teste de 16bit em dois de 8

delay_ms(40);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_out(1,4, "SUCESSSO");
Lcd_out(2,1, "AJUSTE GRAVADO");
delay_ms(800);
atualiza_lcd();

}
// Define Messages


void main() {
trisa.ra0 = 1;
trisa.ra1= 1; //configrada como entrada
trisa.ra2= 1; //configrada como entrada
ADCON1 = 0x82; // configure VDD as Vref, and analog channels

INTCON = 0;
PORTC = 0;
TRISB = 3; //'configura todos os pinos do portd como saída
TRISD = 3; //'configura todos os pinos do portd como saída
TRISE = 0; //'configura todos os pinos do porte como saída
TRISC = 0; //'configura todos os pinos do portd como saída

//'configura AN0,AN1,AN3 COMO analógico e os demais pinos como digital
Gate_Enable = 1;
// TMR1 settings
T1CON.TMR1CS = 0; // Fosc / 4
T1CON.T1CKPS1 = 1; // Setting prescale value to 1:8
T1CON.T1CKPS0 = 1;
PIE1.TMR1IE = 1;
INTCON.PEIE = 1;
INTCON.T0IE = 1;
INTCON.GIE = 1;
Lcd_Init();

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,13, texto);
Lcd_Out(2,13, valor);
atualiza_lcd();

setpoint = eeprom_Read(1);setpoint<<=8;
setpoint |= eeprom_Read(0);

select = 0;
update_select = 1;

do {
if(!SelectButton){
debounce_delay();
update_select = 1;
switch (select) {
case 0 : select=1;
break;
case 1 : select=2;
break;
case 2: select=3;
break;
case 3: select=4;
break;
case 4: select=0;
break;
} //case end
}
if(select == 0){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);


update_select=0;
}
////////////////////********/////
leitura_ad = adc_read(0);
aux = leitura_ad;

leitura_ad = leitura_ad*5000/1023;
texto[0] = (leitura_AD%1000)/100 + 48;
texto[1] = (((leitura_AD%1000)%100)/10) + 48;
texto[2] = '.';
texto[3] = (((leitura_AD%1000)%100)%10) + 48;
Lcd_Out(1,13, texto);

if (Button(&PORTD, 0, 20 ,0)){ //verifica tecla1.
setpoint++;
}

if (Button(&PORTD, 1, 20, 0)){ //verifica se a tecla2.
setpoint--;
}
if (PORTd.Rd5 == 0){ //se portb.rb0 estiver em nivel baixo chama funçao
escreve_eeprom(); //chama a funçao escreve na eeprom
}
if (PORTd.Rd4 == 0 && teste ==1 ){
portc.rc7 = ~portc.rc7;
teste = 0; }
delay_ms(20);
if (PORTd.rd4 == 1 && teste == 0 ){
teste = 1;
delay_ms(20);
}
if(portc.rc7==1){
Lcd_out(2,10, "TL");
} else Lcd_out(2,10, "TD");

valor[0] = (setpoint%100)/10 + 48;
valor[1] = ((setpoint%100)%10) + 48;
valor[2] = '.';
valor[3] = '0';
Lcd_out(2,13, valor);
Lcd_Out(1,1,"TEMPERATURA");
Lcd_Out(2,1,"AJUSTE");
if (aux/2 <= setpoint){
portc.rc0 = 0;
}
else portc.rc0 = 1;
}//FIM DO MENU 0
if(select == 1){ // Diode Tester
if(update_select){

Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"VOLTIMETRO");

update_select=0;
}
// Read Voltage

ADC_Value = ADC_Read(1);
DisplayVolt = ADC_Value * 2;
AdjustVolt = DisplayCurr/1000;
AdjustVolt = 29*AdjustVolt ; // 29 corresponds to 0.286 Ohm
DisplayVolt = DisplayVolt - AdjustVolt;
volt[0] = DisplayVolt/1000 + 48;
volt[1] = (DisplayVolt/100)%10 + 48;
volt[3] = (DisplayVolt/10)%10 + 48;
Lcd_Out(2,9,volt);
Lcd_Out(2,1,Message3);
Lcd_Chr(2,13,'V');
///AQUI VAI OS TEXTO

} // End if (detail_select)

if(select == 2){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"AMPERIMETRO");

update_select=0;
}
// Read Current
ADC_Value = ADC_Read(2);
DisplayCurr = ADC_Value * 17;
amp[0] = DisplayCurr/10000 + 48;
amp[2] = (DisplayCurr/1000)%10 + 48;
amp[3] = (DisplayCurr/100)%10 + 48;
amp[4] = (DisplayCurr/10)%10 + 48;
Lcd_Out(2,10,amp);
Lcd_Chr(2,15,'A');

///AQUI VAI OS TEXTO
} // End if (detail_select)
if(select == 3){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"FREQUENCIMETRO");

update_select=0;
}
// Calculate Frequency
// First begin with prescaler 1:64
OPTION_REG = 0b00110101; // Prescaler (1:64), TOCS =1
prescaler = 64;

Counter = count_pulse();

if (Counter > 99990) {
Display_Freq(Counter);
Lcd_Chr(2,14,'K');
//lowfreq = Counter*1000;
//Lcd_Out(2,1,message5);
//Display_Freq(lowfreq);
}
if (Counter <= 99990) {
OPTION_REG = 0b00111000; // Prescaler (1:1), TOCS =1
prescaler = 1;
Counter = count_pulse();
Counter = 1000*Counter;
Display_Freq(Counter);
Lcd_Chr(2,14,'H');
Lcd_Chr(2,15,'z');
}
Delay_ms(3);
// Ends Frequency display
///AQUI VAI OS TEXTO
} ///FIM DO MENU
if(select == 4){ // Diode Tester
if(update_select){
Lcd_cmd(_LCD_CLEAR);
Lcd_Out(1,1,"CONTA GIRO");

update_select=0;
}


///AQUI VAI OS TEXTO
} ///FIM DO MENU
//iluminacao no lcd liga e desliga
if (PORTd.Rd4 == 0 && teste ==1 ){
portc.rc7 = ~portc.rc7;
teste = 0; }
delay_ms(20);
if (PORTd.rd4 == 1 && teste == 0 ){
teste = 1;
delay_ms(20);
}
if(portc.rc7==1){
;
} else ;


} while(1);
}
// LCD module connections

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!