Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

current control using potentiometer

Status
Not open for further replies.

stereovestro

New Member
currently, im working out on displaying voltage and current onto lcd. but 1st, i need to have a control on the current so that when i decrease or increase the potentiometer, lcd will show the increase or decrease of the current or voltage.

how can i implement the circuit?
 
here are my programming. this is a programme that read the voltage(max voltage 5v microcontroller) from analog to digital on the LCD screen.

by using potentiometer, the value can be adjusted to 1024(max) on the lcd. and it is = to 5v.

i would be grateful if someone could help me.
> instead of displaying 1024 on the screen, i would like to display 5v
> how can i measeure the current at the same time?


#include <p18f4520.h>
#include <delays.h>
#include <stdlib.h>
int result;
void Init_LCD(void);

void W_ctr_4bit(char);
void w_data_4bit(char);

#define LCD_DATA PORTD
#define LCD_RW
#define LCD_RS
#define LCD_E

unsigned char LCD_TEMP, i;
char MESS[11]= "convertion";
char MESS2[4]= " ";

void InterruptHandlerLow(void);
routine
#pragma code InterruptVectorLow= 0x018
void InterruptVectorLow(void) {
_asm
goto InterruptHandlerLow
routine
_endasm
}
#pragma code
#pragma interruptlow InterruptHandlerLow
void InterruptHandlerLow()
{
if(PIR1bits.TMR1IF){
Delay10TCYx(1);
ADCON0bits.GO=1;
while(ADCON0.bits.DONE);
result= ADRESH*256+ADRESL;
//result>>=4;
PORTB=result;
W_ctr_4bit(0xc0);
for(i=0; i<4;i++)
{W_data_4bit(MESS2);
}
W_ctr_4bit(0xc0);
itoa(result,MESS);
i=0;
while(MESS)
{
W_data_4bit(MESS);
i++;}
TMR1H=0x0b;
TMR1L=0xdc;
PIR1bits.TMR1IF=0;
}
}
void main()
{
TRISD=0;
TRISA=0b11110001;
TRISB=0b11110000;
ADCON0=0b00000001;
ADCON1=0b00001110;
ADCON2=0b10000100;

INTCONbits.GIE=0;
Init_LCD();
for(i=o;i<10;i++)
{
W_data_4bit(MESS);
}
PORTB=0b00000110;
RCONbots.IPEN=1;
IPR1bits.TMR1IP=0;
TMR1H=0x0b;
TMR1L=0xdc;
T1CON=0b11110001;
PIR1bits.TMR1IF=0;
PIR1bits.TMR1IE=1;
INCONbits.GIEL=1;
INCONbits.GIE=1;
while(1);
}
void Init_LCD()
{
Delay1kTCYx(15);
W_ctr_4bit(0x03);
Delay1kTCYx(5);
W_ctr_4bit(0x02);
W_ctr_4bit(0b00101000);
W_ctr_4bit(0b00001100);
W_ctr_4bit(0b00000110);
W_ctr_4bit(0b00000001);
}
void W_ctr_4bit(char x)
{
LCD_RW=0;
LCD_RS=0;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1)
}


void W_ctr_4bit(char x)
{
LCD_RW=0;
LCD_RS=1;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1)
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top