*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;
void setup(){
pinMode(analogInput, INPUT);
lcd.begin(16, 2);
lcd.print("DC VOLTMETER");
}
void loop(){
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
lcd.setCursor(0, 1);
lcd.print("INPUT V= ");
lcd.print(vin);
delay(500);
}
//PIC16F886 with 3-wire LCD Experiments with CCS C Ver. 4.140
//LCD module connections
#define LCD_DATA_PIN PIN_B0
#define LCD_CLOCK_PIN PIN_B1
#define LCD_EN_PIN PIN_B2
//End LCD module connections
#include <16F886.h>
#device ADC = 10
#fuses HS,NOWDT,NOMCLR,NOPROTECT,NOLVP
#use delay(clock = 8000000)
#include <3WireLCD.c>
int value = 0;
int16 BV;
float vin = 0.0;
float vout= 0.0;
float R1 = 100000.0; // 100k
float R2 = 10000.0; // 10k
void main()
{
lcd_initialize(); // Initialize LCD module
lcd_cmd(LCD_CLEAR); // Clear the LCD
//*********************************** FIRST ROW ************************
lcd_goto(1, 1); // Go to column 3 row 1
printf(lcd_out, "MY FIRST LCD PROJECT"); //These are Static on the LCD
//********************************* SECOND ROW ***********************
lcd_goto(1, 2); // Go to column 4 row 2
printf(lcd_out, "INPUT: ( V)( Hz)"); //These are Static on the LCD
//******************************** THIRD ROW ****************************
lcd_goto(1, 3); // Go to column 4 row 3
printf(lcd_out, "OUTPUT: ( V)( Hz)"); //These are Static on the LCD
//******************************** FOURTH ROW ***************************
lcd_goto(1, 4); // Go to column 4 row 4
printf(lcd_out, "BATTERY: VDC"); //These are Static on the LCD
delay_ms(200);
setup_adc(ADC_CLOCK_DIV_8); // 8Tosc ADC conversion time
setup_comparator(NC_NC_NC_NC); // disable comparator module
delay_ms(10);
setup_adc_ports( sAN0); // Select Analog Inputs
set_adc_channel(0); //Select AN0 as ADC Input for BV
delay_ms(1); //Wait 1 ms
BV = read_adc(); //Read AN0 and stor in BV
delay_ms(1); //Wait 1 ms
vout = (value* 5.0)/1024.0;
vin = vout/(R2/(R1+R2));
if (vin<0.09)
{
vin=0.0; //statement to kill undesired reading !
}
{
lcd_goto(10,4);
printf(lcd_out,"%s",vin); // I want the Vin to display its value here
delay_ms(10);
}
while(TRUE)
{
}
}
What does this mean?I know I can't try such circuit in hardware.
Hi,
What does this mean?
And what do you gain from such a simulation?
Klaus
The same applies here: Why not in simulation?I even connected 5V1 zener diode between ADC pin and ground.
Hi,
to me it makes no sense:
* to use the pot in reality, because it won´t withstand the voltage
* to simulate the pot... when you don´t use it in reality (and you already know that it does not work in reality)
Why make the simulation different to your real circuit.
The same applies here: Why not in simulation?
My recommendation: Include the zener in simulaton and see the big difference (measurement error) the zener causes when measuring high voltage.
I assume it makes voltage measurement above 35V almost impossible (depending on zener type and temperature)
--> It´s your choice whether the simulation is able to show you design errors beforehand...
Klaus
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1 Sec
My question is, to some people here who handle Arduino as well as Pic Microcntrollers, how can I convert this type of Arduino Code to C? ;
My question is, to some people here who handle Arduino as well as Pic Microcntrollers, how can I convert this type of Arduino Code to C?
Code:uint32_t start_time = millis(); while((millis()-start_time) < 1000) //sample for 1 Sec
I've not used CCS C for many (many) years but it has a built-in/library function called 'delay_ms'
Well, I know that Arduino C also. I would have better addressed it as Arduino syntax or style.
//PIC16F886 with 3-wire LCD Experiments with CCS C Ver. 4.140
////////////////////////////////////////////////////////////////////
/** //
//
#include <LiquidCrystal.h> //
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //
int analogInput = 0; //
float vout = 0.0; //
float vin = 0.0; //
float R1 = 100000.0; // resistance of R1 (100K) -see text! //
float R2 = 10000.0; // resistance of R2 (10K) - see text! //
int value = 0; //
void setup() //
{ //
pinMode(analogInput, INPUT); //
lcd.begin(16, 2); //
lcd.print("DC VOLTMETER"); //
} //
void loop() //
{ //
// read the value at analog input //
value = analogRead(analogInput); //
vout = (value * 5.0) / 1024.0; //
vin = vout / (R2/(R1+R2)); //
if (vin<0.09) { //
vin=0.0;//statement to quash undesired reading ! //
} //
lcd.setCursor(0, 1); //
lcd.print("INPUT V= "); //
lcd.print(vin); //
delay(500); //
} /////////////////////////////////////////////////////////////////
**/
/** I wanted to convert the above Arduino code to CCS C Code but VOLTAGE could
not be displayed. The circhiut works fine in Arduino.
**/
//LCD module connections
#define LCD_DATA_PIN PIN_B0
#define LCD_CLOCK_PIN PIN_B1
#define LCD_EN_PIN PIN_B2
//End LCD module connections
#include <16F886.h>
#device ADC = 10
#fuses HS,NOWDT,NOMCLR,NOPROTECT,NOLVP
#use delay(clock = 8000000)
#include <3WireLCD.c>
int16 value =0;
float vin = 0.0;
float vout= 0.0;
float R1 = 100000.0; // 100k
float R2 = 10000.0; // 10k
void init()
{
setup_adc(ADC_CLOCK_DIV_8); // 8Tosc ADC conversion time
setup_adc_ports( sAN0); // Select Analog Inputs
delay_ms(10);
}
void main()
{
init(); // Configure peripherals/hardware
lcd_initialize(); // Initialize LCD module
delay_ms(100);
lcd_cmd(LCD_CLEAR); // Clear the LCD
lcd_goto(5, 1); // Go to column 5 row 1
printf(lcd_out, "DC VOLTMETER");
while(TRUE)
{
set_adc_channel(0); //Select AN0 as ADC Input for BV
delay_ms(1); //Wait 1 ms
value = read_adc(); //Read AN0 and stor in BV
delay_ms(1); //Wait 1 ms
vout = (value* 5.0)/1024.0;
delay_ms(1);
vin = (vout/(R2/(R1+R2)))+0.05;
if (vin<0.09)
{
vin=0.0; //statement to kill undesired reading !
}
{
lcd_goto(1,4); // Go to column 1 row 4
printf(lcd_out,"Voltage = %3.1gV",vin); // Display Voltage Value
delay_ms(100);
}
}
}
That doesn't change the fact that it is best for you to learn how to code in C and know your compiler(s), then you could easily translate syntax.
You can only translate Chinese to French if you know both languages, or you can obviously use Google translate but then the French wouldn't understand the meaning. Same goes for compilers.
e.g. "uint32_t start_time = millis();" Is a variable declaration and value assignment in one line.
Maybe the CSS compiler doesn't use "uint32_t" to declare a unsigned 32bit integer, check the CSS reference manual https://www.ccsinfo.com/downloads/ccs_c_manual.pdf. And maybe the CSS compiler doesn't allow variable declaration and value assignment in one line, check the CSS reference manual. In which case the translated line looks like this, and you would have to write the millis() function yourself:
unsigned int32 start_time;
start_time = millis();
Then you have "while((millis()-start_time) < 1000)" which is a simple standard while loop.
I don't find any reason in the CSS reference manual to why this shouldn't work as is. If it gives you a syntax error then let me know the error message. Again you would have to write the millis() function yourself.
Now repeat above for every line of code you want to translate.
@ Swend, thanks for your guidelines. This is what I needed to be told. You know some experts talk to some beginners without knowing if they have even attained a medium skill in programming. Some of those expert suggestions without an example may even throw the poster to a more confused situation.
Thanks again for your explanations
vin = (vout/(R2/(R1+R2)))+0.05;
vin = vout * 11 + 0.05;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?