Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help in 16F874 Programming

Status
Not open for further replies.

Shamooooot

Newbie level 6
Newbie level 6
Joined
Jan 1, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,420
NEED HELP PLEASE!!!:-(

int t;
unsigned int adcvalue;

//LCD pinout settings

sbit LCD_RS at Rc3_bit;
sbit LCD_EN at Rc5_bit;
sbit LCD_d0 at Rb0_bit;
sbit LCD_d1 at Rb1_bit;
sbit LCD_d2 at Rb2_bit;
sbit LCD_d3 at Rb3_bit;
sbit LCD_d4 at Rb4_bit;
sbit LCD_d5 at Rb5_bit;
sbit LCD_d6 at Rb6_bit;
sbit LCD_d7 at Rb7_bit;

//Pin direction

sbit LCD_RS_Direction at TRISc3_bit;
sbit LCD_EN_Direction at TRISc5_bit;
sbit LCD_d0_Direction at TRISB0_bit;
sbit LCD_d1_Direction at TRISB1_bit;
sbit LCD_d2_Direction at TRISB2_bit;
sbit LCD_d3_Direction at TRISB3_bit;
sbit LCD_d4_Direction at TRISB4_bit;
sbit LCD_d5_Direction at TRISB5_bit;
sbit LCD_d6_Direction at TRISB6_bit;
sbit LCD_d7_Direction at TRISB7_bit;

void main()
{
TRISA = 0xFF; // PORTA Input
LCD_Init();
LCD_out(1,4,"J.U.S.T");
delay_ms(100);
LCD_out(1,3,"Biomedical");
LCD_out(2,3,"Engineering");
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
delay_ms(100);
LCD_out(1,4,"Done By");
LCD_out(2,3,"M.Juhair");
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
LCD_out(1,4,"& M. Fahed");
LCD_out(2,3,"& A.Jroud");
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);
LCD_out(1,1,"Supervised By Dr.");
LCD_out(2,1,"Areen Al-Basheer");
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);

while (1) {
t = ADC_read(2); // get ADC value from 2nd channel
adcvalue=t;
}
if (adcvalue>>2) {
LCD_out(1,1,"RATE/MIN=(30)");
}
}

The Micro controller in the normal case it receives once Low and once high in ordered or not ordered intervals on its A2 input, and in each interval (in a minute for example) it shows the number of transition from low to high or vice versa. For example it shows on the screen:
RATE PER MIN = ("number of transitions")
OK…
but when input becomes low for 10 or more seconds, a clock starts on the screen and it counts for two minutes. Once input comes high to the PIN 2 the program back to it's normal mode for example "RATE PER MIN = (30)". But if the 2 minutes completed the screen shows:
WARNING !!!
Oxygenated Blood Problem
and a buzzer connected on D7 for example is activated

"My biggest concern is that I can't get the value on A2 input to compare it in an if statement with 2 volts for example
if (adcvalue>>2) {
LCD_out(1,1,"RATE/MIN=(30)");
} even though the condition is true"

Thanks in advance :D
 

Did it nothing happened ??
you mean like this:

if ( adcvalue>>2) {
LCD_out(1,1,"RATE/MIN=(30)");
}
 

Keith is right, he means that your if statement
"if (adcvalue>>2)" shifts value stored in adcvalue, 2 times right.

You should give this: "if (adcvalue>2)" it means if the value stored in adcvalue is greater than 2 then condition is true.
 

well thank you but still the "RATE/MIN=(30)" doesn't displayed on the LCD even though the voltage on A2 input is more than 2 volt!!
 

You need to trace the values through the code. What is the value of "t", for example? What is the value of "adcvalue"?

Also, I am not sure why you assign an "int" to an "unsigned int" but there may be type casting issues depending on the compiler. I would normally explicitly cast to be sure.

Keith.
 

Dear keith
I am trying to assign t (and hence adcvalue) to the voltage input to the pin A2 of the PIC the Proteus shows this voltage to be between 2 and 3 volts which should satisfy the condition of the if-statement !!
 

I don't know which compiler you are using so I don't know exactly what ADC_read(2) will return but I would normally expect an ADC value to be a hex value and certainly not in volts. As I said earlier, use the debugger to see what the value of t and adcvalue really is!

Keith.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top