Hello sir .
I have issue about config pic16f1575 to ADC and show lcd16x2 my code:
config bit mcu :osc=external clk 16Mhz ,MCLR = MCLR enable ,CLKOUT = CLK out function anabled on the clkoutpin ,PLL = 4x disabled
program power_factor;
//program show ampere meter AC.230v
// LCD module connections
var LCD_RS : sbit at RC4_bit;
LCD_EN : sbit at RC5_bit;
LCD_D4 : sbit at RC0_bit;
LCD_D5 : sbit at RC1_bit;
LCD_D6 : sbit at RC2_bit;
LCD_D7 : sbit at RC3_bit;
LCD_RS_Direction : sbit at TRISC4_bit;
LCD_EN_Direction : sbit at TRISC5_bit;
LCD_D4_Direction : sbit at TRISC0_bit;
LCD_D5_Direction : sbit at TRISC1_bit;
LCD_D6_Direction : sbit at TRISC2_bit;
LCD_D7_Direction : sbit at TRISC3_bit;
// End LCD module connections
const
character: array[0..7] of byte = (4,14,31,27,31,14,4,0); // for charecter LCD
amperei=2; // Set port current = AN2
g_i=30; // Ai gain = 1 (Vin op-amp = 0-2.5v ) 0-100A ,R burden=50 ohm
var
current,current1:word; //Datatype for Current i/p
value5:real;
y1,y2,y3,y4,y5,yv1,yv2,yv3,yv:real;
temp:word;
//Ch0,ADR:word;
oldstate : byte;
ok:array[23] of char;
procedure xxxx;
............
............
egin
{ Main program }
// comparator off
CM1CON0:=0; // comparator off
OPTION_REG:=0; // pull up port A
TRISA:=%00001111; //Set Ra1 = input verf+
LATA:=0;
ANSELA:=%00000110; //Config port A as analog AN1,AN2 another digital;
TRISC:=0; //Cconfig portC as output
PORTC:=0;
ANSELC:=0; //Config portc as analog I/O
LATC:=0;
ADCON0:=%00001000; //AN2=CurrentI ,
ADCON1:=%00100010; //AN0=digital ,AN1=Vref+=4 ,AN2=input I ,left justify
ADCON2:=0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1, 3, ' Amps_meter');
Lcd_out(2, 16, 'A');
Lcd_out(2, 3, ' 0.00 ');
{
Lcd_out(1, 3, ' Amps_meter');
Lcd_out(2, 16, 'A');
}
//Initial first value
current:=0;
while true do
begin
test_sw(1);
case oldstate of
0:show_pfc;
end;
end;//while principal;
end.
My issue complier pass but not working sir.
any one can help me.
to configurator sir my english is weak .(from thailand people)
I use pic16f688 is ok work to ADC and LCD but memory small to use detect current constant sir. but 16f1575 more memory but not work i think config at main program issue sir.
I used mplabx IPE 4.05 to programmer pass all(pickit3 clone) . for pic16f688 used pickit2
how to config bit pic16f1575 to ADC and lcd16x2
Re: how to config bit pic16f1575 to ADC and lcd16x2
Hi,
First of all, try simplifying the code by using only Lcd or ADC, to see if each of them works separately.
Secondly, use LAT registers for Lcd instead or PORT, like this :
Regards,
Filip.
First of all, try simplifying the code by using only Lcd or ADC, to see if each of them works separately.
Secondly, use LAT registers for Lcd instead or PORT, like this :
Code: Select all
var LCD_RS : sbit at LATC4_bit;
LCD_EN : sbit at LATC5_bit;
LCD_D4 : sbit at LATC0_bit;
LCD_D5 : sbit at LATC1_bit;
LCD_D6 : sbit at LATC2_bit;
LCD_D7 : sbit at LATC3_bit;
LCD_RS_Direction : sbit at TRISC4_bit;
LCD_EN_Direction : sbit at TRISC5_bit;
LCD_D4_Direction : sbit at TRISC0_bit;
LCD_D5_Direction : sbit at TRISC1_bit;
LCD_D6_Direction : sbit at TRISC2_bit;
LCD_D7_Direction : sbit at TRISC3_bit;
Filip.
Re: how to config bit pic16f1575 to ADC and lcd16x2
thank you sir. i will try
Re: how to config bit pic16f1575 to ADC and lcd16x2
hello sir my code for lcd16x2 work already my code from mikroElektronika but configuration port C as digital output:
program Lcd_Test;
// LCD module connections
var LCD_RS : sbit at LATC4_bit;
var LCD_EN : sbit at LATC5_bit;
var LCD_D4 : sbit at LATC0_bit;
var LCD_D5 : sbit at LATC1_bit;
var LCD_D6 : sbit at LATC2_bit;
var LCD_D7 : sbit at LATC3_bit;
var LCD_RS_Direction : sbit at TRISC4_bit;
var LCD_EN_Direction : sbit at TRISC5_bit;
var LCD_D4_Direction : sbit at TRISC0_bit;
var LCD_D5_Direction : sbit at TRISC1_bit;
var LCD_D6_Direction : sbit at TRISC2_bit;
var LCD_D7_Direction : sbit at TRISC3_bit;
// End LCD module connections
var txt1 : array[16] of char;
txt2 : array[9] of char;
txt3 : array[8] of char;
txt4 : array[7] of char;
i : byte; // Loop variable
procedure Move_Delay(); // Function used for text moving
begin
Delay_ms(500); // You can change the moving speed here
end;
begin
ANSELC := 0; // Configure PORTB pins as digital
txt1 := 'mikroElektronika';
txt2 := 'EasyPIC7';
txt3 := 'Lcd4bit';
txt4 := 'example';
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_Out(1,6,txt3); // Write text in first row
LCD_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
LCD_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(500);
// Moving text
for i:=0 to 3 do // Move text to the right 4 times
begin
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
end;
while TRUE do // Endless loop
begin
for i:=0 to 7 do // Move text to the left 8 times
begin
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
end;
for i:=0 to 7 do // Move text to the right 8 times
begin
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
end;
end;
end.
program Lcd_Test;
// LCD module connections
var LCD_RS : sbit at LATC4_bit;
var LCD_EN : sbit at LATC5_bit;
var LCD_D4 : sbit at LATC0_bit;
var LCD_D5 : sbit at LATC1_bit;
var LCD_D6 : sbit at LATC2_bit;
var LCD_D7 : sbit at LATC3_bit;
var LCD_RS_Direction : sbit at TRISC4_bit;
var LCD_EN_Direction : sbit at TRISC5_bit;
var LCD_D4_Direction : sbit at TRISC0_bit;
var LCD_D5_Direction : sbit at TRISC1_bit;
var LCD_D6_Direction : sbit at TRISC2_bit;
var LCD_D7_Direction : sbit at TRISC3_bit;
// End LCD module connections
var txt1 : array[16] of char;
txt2 : array[9] of char;
txt3 : array[8] of char;
txt4 : array[7] of char;
i : byte; // Loop variable
procedure Move_Delay(); // Function used for text moving
begin
Delay_ms(500); // You can change the moving speed here
end;
begin
ANSELC := 0; // Configure PORTB pins as digital
txt1 := 'mikroElektronika';
txt2 := 'EasyPIC7';
txt3 := 'Lcd4bit';
txt4 := 'example';
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_Out(1,6,txt3); // Write text in first row
LCD_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
LCD_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(500);
// Moving text
for i:=0 to 3 do // Move text to the right 4 times
begin
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
end;
while TRUE do // Endless loop
begin
for i:=0 to 7 do // Move text to the left 8 times
begin
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
end;
for i:=0 to 7 do // Move text to the right 8 times
begin
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
end;
end;
end.
Re: how to config bit pic16f1575 to ADC and lcd16x2
Hello sir
The anser for config bit for LCD and analog to digital with Vref external +4v from my code for pic16f1575 sir.
program power_factor;
//program show ampere meter AC.230v.
//PIC 16F1575 ,external OSC = 16MHz ,PLL = OFF ,MCLR = function mclr.
// LCD module connections
var LCD_RS : sbit at LATC4_bit;
var LCD_EN : sbit at LATC5_bit;
var LCD_D4 : sbit at LATC0_bit;
var LCD_D5 : sbit at LATC1_bit;
var LCD_D6 : sbit at LATC2_bit;
var LCD_D7 : sbit at LATC3_bit;
var LCD_RS_Direction : sbit at TRISC4_bit;
var LCD_EN_Direction : sbit at TRISC5_bit;
var LCD_D4_Direction : sbit at TRISC0_bit;
var LCD_D5_Direction : sbit at TRISC1_bit;
var LCD_D6_Direction : sbit at TRISC2_bit;
var LCD_D7_Direction : sbit at TRISC3_bit;
// End LCD module connections
const
character: array[0..7] of byte = (4,14,31,27,31,14,4,0); // for charecter LCD
amperei=2; // Set port current = AN2
g_i=30; // Ai gain = 1 (Vin op-amp = 0-2.5v ) 0-100A ,R burden=50 ohm
var
current,current1:word; //Datatype for Current i/p
value5:real;
y1,y2,y3,y4,y5,yv1,yv2,yv3,yv:real;
temp:word;
//Ch0,ADR:word;
oldstate : byte;
ok:array[23] of char;
procedure xxxx;
..............
..............
begin
{ Main program }
ANSELA:=%00000110; //Config port A as analog AN1,AN2 another digital,AN0 for trig zero crossing with analog
ANSELC:=0; //Config portc as analog I/O
TRISA:=%00001111; //Set RA0 = input zero ,RA1=verf+ and AN2 with input AC current
C1ON_bit := 0; // Disable comparators
C2ON_bit := 0;
ADCON0:=%00001000; //AN2=CurrentI ,
ADCON1:=%00100010; //AN0=digital ,AN1=Vref+=4 ,AN2=input I ,left justify
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1, 3, ' Amps_meter');
Lcd_out(2, 16, 'A');
Lcd_out(2, 3, ' 0.00 ');
//Initial first value
current:=0;
while true do
begin
test_sw(1);
case oldstate of
0:show_pfc;
end;
end;//while principal;
end.
after test my code maybe i have some issue for zero for next new post sir. but now config for lcd and a_to_d ok.
The anser for config bit for LCD and analog to digital with Vref external +4v from my code for pic16f1575 sir.
program power_factor;
//program show ampere meter AC.230v.
//PIC 16F1575 ,external OSC = 16MHz ,PLL = OFF ,MCLR = function mclr.
// LCD module connections
var LCD_RS : sbit at LATC4_bit;
var LCD_EN : sbit at LATC5_bit;
var LCD_D4 : sbit at LATC0_bit;
var LCD_D5 : sbit at LATC1_bit;
var LCD_D6 : sbit at LATC2_bit;
var LCD_D7 : sbit at LATC3_bit;
var LCD_RS_Direction : sbit at TRISC4_bit;
var LCD_EN_Direction : sbit at TRISC5_bit;
var LCD_D4_Direction : sbit at TRISC0_bit;
var LCD_D5_Direction : sbit at TRISC1_bit;
var LCD_D6_Direction : sbit at TRISC2_bit;
var LCD_D7_Direction : sbit at TRISC3_bit;
// End LCD module connections
const
character: array[0..7] of byte = (4,14,31,27,31,14,4,0); // for charecter LCD
amperei=2; // Set port current = AN2
g_i=30; // Ai gain = 1 (Vin op-amp = 0-2.5v ) 0-100A ,R burden=50 ohm
var
current,current1:word; //Datatype for Current i/p
value5:real;
y1,y2,y3,y4,y5,yv1,yv2,yv3,yv:real;
temp:word;
//Ch0,ADR:word;
oldstate : byte;
ok:array[23] of char;
procedure xxxx;
..............
..............
begin
{ Main program }
ANSELA:=%00000110; //Config port A as analog AN1,AN2 another digital,AN0 for trig zero crossing with analog
ANSELC:=0; //Config portc as analog I/O
TRISA:=%00001111; //Set RA0 = input zero ,RA1=verf+ and AN2 with input AC current
C1ON_bit := 0; // Disable comparators
C2ON_bit := 0;
ADCON0:=%00001000; //AN2=CurrentI ,
ADCON1:=%00100010; //AN0=digital ,AN1=Vref+=4 ,AN2=input I ,left justify
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1, 3, ' Amps_meter');
Lcd_out(2, 16, 'A');
Lcd_out(2, 3, ' 0.00 ');
//Initial first value
current:=0;
while true do
begin
test_sw(1);
case oldstate of
0:show_pfc;
end;
end;//while principal;
end.
after test my code maybe i have some issue for zero for next new post sir. but now config for lcd and a_to_d ok.