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.

LCD is not displaying numerical character in the project.

Status
Not open for further replies.

Mr.Electronist

Newbie level 1
Joined
Apr 6, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Pakistan
Activity points
1,335
Hello Fellows.

I am designing a health calculator gadget for patients. Its hardware consists of pic16f877, LCD and two Switches and software for simulation are Mikroc and Proteus.

The calculator asks 36 Qs (from txt[8] to txt[44]) from the patient and their total score is displayed on the LCD in the end.

so I designed the code in the following way,

when 1st Question appears on LCD, the user can ans it by Yes/No Switches. if user presses yes, 1 is added (incremented) in the score, else if user presses no, score remains same and next Qs appears. the code should wait for the user input and then moves to next Question.

This repeats for all 36 Questions.

so i started writing the code for first two questions and checking whether the toal score of Questions is displaying in the LCD accordingly or not. The Problem is that I am unable to make above conditions properly.
in my following code when 1st Question appears, i press yes, then it goes to 2nd Question (which is fine) but in the end total score (which should be 2) is not displayed in LCD. and if i press no push button, nothing happens.

can u help me with this issue where i am wrong or how to make above condition for just two starting Qs?


Code.



sbit LCD8_RS at RD0_bit;
sbit LCD8_RW at RD1_bit;
sbit LCD8_EN at RD2_bit;
sbit LCD8_D7 at RB7_bit;
sbit LCD8_D6 at RB6_bit;
sbit LCD8_D5 at RB5_bit;
sbit LCD8_D4 at RB4_bit;
sbit LCD8_D3 at RB3_bit;
sbit LCD8_D2 at RB2_bit;
sbit LCD8_D1 at RB1_bit;
sbit LCD8_D0 at RB0_bit;

sbit LCD8_RS_Direction at TRISD0_bit;
sbit LCD8_RW_Direction at TRISD1_bit;
sbit LCD8_EN_Direction at TRISD2_bit;
sbit LCD8_D7_Direction at TRISB7_bit;
sbit LCD8_D6_Direction at TRISB6_bit;
sbit LCD8_D5_Direction at TRISB5_bit;
sbit LCD8_D4_Direction at TRISB4_bit;
sbit LCD8_D3_Direction at TRISB3_bit;
sbit LCD8_D2_Direction at TRISB2_bit;
sbit LCD8_D1_Direction at TRISB1_bit;
sbit LCD8_D0_Direction at TRISB0_bit;
// End Lcd8 module connections


// calculator parameters

char txt0[] = "Health";
char txt1[] = "Calculator";
char txt2[] = "Designed By";
char txt3[] = "A5SOLUTIONS";
char txt4[] = "VTRF Assessment";
char txt5[] = "Enter Your Ans";
char txt6[] = "Use SW1 for Yes";
char txt7[] = "Use SW2 for No";
char txt8[] = "Age 41-60 Years?";
char txt9[] = "Swollen Legs?";
char txt10[] = "Varicose Veins?";
char txt11[] = "Obescy (BM>25)?";
char txt12[] = "Minor Surgery Planned?";
char txt13[] = "Seosis (<1 Month)?";
char txt14[] = "Serious Lung Disease Including Pneumonia (<1 Month)?";
char txt15[] = "Oral Contraceptives or Hormone Replacement Therapy?";
char txt16[] = "Pregnancy or Postmortem (<1 Month)?";
char txt17[] = "History of unexplained stillborn infant, Recurrent Spontaneous Abortion (>3). Premature birth with Toxemia or growth-restricted infant?";
char txt18[] = "Acute Myocardial Infarction?";
char txt19[] = "Congestive Heart Failure (<1 Month)?";
char txt200[] = "Medical Patient currently at bed rest?";
char txt20[] = "History of Inflammatory Bowel Disease?";
char txt21[] = "History of Prior Major Surgery (<1 Month)?";
char txt22[] = "Abnormal Pulmonary Function (COPD)?";
char txt23[] = "Other Risk Factors?";
char txt24[] = "Age 61-74?";
char txt25[] = "Anthroscopic Surgery?";
char txt26[] = "Malignancy (Present or Previous)?";
char txt27[] = "Laparoscopic Surgery (>45 Minutes)?";
char txt28[] = "Patient confined to bed (>72 Hours)?";
char txt29[] = "Immobilizing Plaster Cast (<1 Month)?";
char txt30[] = "Age 75 Years or Older?";
char txt31[] = "History of DVT/PE?";
char txt32[] = "Positive Factor V Leiden?";
char txt33[] = "Elevated Serum Homocysteine?";
char txt34[] = "Heparin-Induced Thrombocytopenia (HIT)?";
char txt35[] = "Elevated Anti-cardiolipin Antibodies?";
char txt36[] = "Other Congenital or Acquired Thrombophilia?";
char txt37[] = "Family History of Thrombosis?";
char txt38[] = "Positive Prothrombin 20210A?";
char txt39[] = "Positive Lupus Anticoagulant?";
char txt40[] = "Stroke (<1 Month)?";
char txt41[] = "Elective Major Lower Extremity Anthroplasty?";
char txt42[] = "Hip Pelvis or Leg Fracture (<1 Month)?";
char txt43[] = "Acute Spinal Cord Injury (paralysis) (<1 Month)?";
char txt44[] = "Multiple Trauma (<1 month)?";
char txt45[] = "VTRF Score is";


char i; // Loop variables
char t;
char x[2];

void Move_Delay() { // Function used for text moving
Delay_ms(100); // You can change the moving speed here
}

void main(){

//IRP_bit = 1;
//ANSEL = 0; // Configure AN pins as digital I/O
//ANSELH = 0;
//C1ON_bit = 0; // Disable comparators
//C2ON_bit = 0;

Lcd8_Init(); // Initialize Lcd8

Lcd8_Cmd(_LCD_CLEAR); // Clear display

Lcd8_Out(1,6,txt0); // Write text in first row
Lcd8_Out(2,4,txt1); // Write text in second row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display

Lcd8_Out(1,4,txt2); // Write text in first row
Lcd8_Out(2,4,txt3); // Write text in second row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display

Lcd8_Out(1,1,txt4); // Write text in first row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display
Lcd8_Cmd(_LCD_CURSOR_OFF); // Cursor off


Lcd8_Out(1,1,txt5); // Write text in first row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display

Lcd8_Out(1,1,txt6); // Write text in first row
Lcd8_Out(2,1,txt7); // Write text in second row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display

//Q1

Lcd8_Out(1,1,txt8); // Write text in first row
Delay_ms(100); // wait for user input

//switch controlling

TRISD = 0b11111000;
PORTD = 0b11111000;

wait: if (PORTD.F3=1)
{ t++;
goto next;
}
else if (PORTD.F4=0)
{ --t;
goto next;
}
else
goto wait;

next: delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display


//Q2

Lcd8_Out(1,1,txt9); // Write text in first row
Delay_ms(100); // wait for user input

//switch controlling

wait1: if (PORTD.F3=1)
{ t++;
goto next1;
}
else if (PORTD.F4=0)
{ --t;
goto next1;
}
else
goto wait1;

next1:
delay_ms(100);

bytetostr(t,x);

//Result Display

Lcd8_Cmd(_LCD_CLEAR); // Clear display
Lcd8_Out(1,1,txt45); // Write text in first row
Lcd8_Out(2,2,x); // Write text in second row
} untitled.JPG
 

Hello!

I don't really know what you expect, but for example these lines
Lcd8_Out(1,6,txt0); // Write text in first row
Lcd8_Out(2,4,txt1); // Write text in second row
Delay_ms(100);

Lcd8_Cmd(_LCD_CLEAR); // Clear display

Lcd8_Out(1,4,txt2); // Write text in first row
Lcd8_Out(2,4,txt3); // Write text in second row
Delay_ms(100);
will write so fast that you don't have time to input anything. You firs write "Health calculator", then
100 ms later "designed by ..."
And everything alike.

Now you use:

TRISD = 0b11111000;
PORTD = 0b11111000;
Are we supposed to guess what it means?

Now the impression I have:
Apparently you don't master the concept of functions. All your questions should be treated the
same way. I would create a function "Question".

Code:
int8 Question(char * questionstring) {
    Display(questionstring);
    WaitForButton(TIMEOUT);  // You may add a timeout to avoid to lock the program or no timeout at all in order to wait forever for reply
    if(reply == YesButton) return 1;
    return 0;
}
Once done, you can write for instance:

Code:
int result = 0;
for(i = = ; i < NQuestions ; ++i) {
   result += Question(i);
}

And if you do this, you might consider to do:
Code:
char * info[] {
    "Health",
    "Calculator",
    "Designed By",
    etc....
}

char * Question[] {
    "Age 41-60 Years?"
    "Swollen Legs?"
    etc...
}
If you do like this and iterate questions:
1. You can add information in the first buffer without changing all your questions indexes.
2. Similarily, you can alter the questions anytime.

Code structure suggestion:

1. In Info.h / Info.c, write the information related data
2. In Questions.h / Questions.c, write your questions data.
3. Write a DisplayInfo function displaying the above (1) information.
4. Write a question function which will operate the same fore each of your 36 questions.
This question should return a result for each question.
5 Write a loop for all your questions.

Hint: you should NEVER use even a single GOTO in a C program. I don't know why this word
has been kept in the C keywords, but it's the best way to create bugs.

One good way to program is to use a "top to bottom" design and you do apparently the opposite.

Basically, you want to submit a bunch of questions to a patient.
All the questions expect a yes/no reply. By the way you could even think about a "backwards"
button to modify the previous questions. If you do this in linear code as you just did, then you
will have to rewrite everything if your boss asks you to do so.

Id you do everything linearly then you have to change the program every time there are other
questions. If you do it as indicated above, then if you have to insert a question between question
14 and 15, you just insert one line and that's it.


Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top