CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

LMB204BDC with Flex 4 x 20 driver not displaying text
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sat Jun 09, 2012 8:41 pm     Reply with quote

PCM programmer wrote:
That switch circuit can't supply two logic states. With that circuit, the PIC
pin is either a floating input or it's a logic "1". You need to fix that.
Change them all to the schematic that I posted. You will also need to
change the logic of your code to look for a logic "0" as the active state of
the switches.

If your switches are connected to pins on PortB, then you can enable
the built-in PortB pullups and save yourself from having to add the
resistors. All you have to do in that case is change the +5v connection
to be Ground instead.


Is there a way to make it work using my current setup? Because there is no way that I can change it now (This thing is due today and with the jumble of wires I have I cant desolder joints), I always thought that switches should have an output of either one or zero, one being 5v and zero being 0v
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 09, 2012 8:53 pm     Reply with quote

You need to do something similar to what I describe in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=18121
You have the switch wired the opposite way from that thread. You have
it wired to +5v instead of to Ground. But I think the basic idea can still
work. The logic of the code would have to be changed and tested.
I can't do that right now. I can do it tomorrow afternoon. Or maybe
you can figure it out. But don't burn up any more PICs.


Re this question:
Quote:

I always thought that switches should have an output of either one or zero, one being 5v and zero being 0v

That is correct, but your switch circuit doesn't do that. It puts out "nothing" or +5v. It does not put out "0v" or "+5v".
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 11:31 am     Reply with quote

PCM programmer wrote:

Code:

           +5v
            |
            <
            > 4.7K       
            <         ___  Switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
                              --- GND
                               -   





I got an extended time from my teacher and I think I have time to use this setup, however, when I do so will input(BTN_A) == 0 be equal to the button being pushed? And also does the resistor need to be 4.7K? If not, what can the value be?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 11:42 am     Reply with quote

You can use 10K or any reasonable value.

Yes, when the button is pressed it will be read as a Logic 0 by the PIC.
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 11:52 am     Reply with quote

PCM programmer wrote:
You can use 10K or any reasonable value.

Yes, when the button is pressed it will be read as a Logic 0 by the PIC.


Ok I'm going to try and tell you my results.
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 12:01 pm     Reply with quote

PCM programmer wrote:
You can use 10K or any reasonable value.

Yes, when the button is pressed it will be read as a Logic 0 by the PIC.

Can I use 1k ohm resistors?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 12:27 pm     Reply with quote

Yes, that will work.
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 1:25 pm     Reply with quote

PCM programmer wrote:
Yes, that will work.


I used different resistor values for each button (as I cannot find equal values), this is how my buttons are wired:

Code:

             +5v
         |---|---|
         <   <   <
         >R1 >R2 > R3       
         <   <   <    ___  Switch A
To       |   |   |   _|_|_
PIC -------------x---o   o---------x
         |   |        ___  Switch B|
To       |   |       _|_|_         |
PIC ---------x-------o   o---------x
         |            ___  Switch C|
To       |           _|_|_         |
PIC -----x-----------o   o---------x
                                   |
                              GND ___
                                   -


R1 = 1K ohm
R2 = 2K ohm
R3 = 9.5K ohm

I think this results in the electrons 'preferring' to go through the R1 resulting in the push to be read as switch C's result. The only resistors I have many of are 330 ohm resistors (I use them to power LEDs from 5v) are these significant enough? Can I use them in this circuit?

Thanks in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 1:39 pm     Reply with quote

Come on, you are spending way too much time on this. The resistor
size doesn't matter that much. Having 3 different sizes doesn't matter.
I hope you have the output of each circuit connected to a different PIC pin.
That's what you should have.

You need to move on from this, and do the rest of your project.
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 1:42 pm     Reply with quote

PCM programmer wrote:
You need to move on from this, and do the rest of your project.

I finished the rest, all the code is done also, but the only last problem is the push buttons, none of them do anything except button C, which has the 1k Resistor. Here's my code for this project (I know it's not the most efficient and I didn't use best practices but here it is anyway)

Code:

#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)

#include <Flex_LCD420.c>
#include <7segDisp.c>

#define btn_A PIN_C4
#define btn_B PIN_C5
#define btn_C PIN_C6


void testScreen(){
   // Test the clear screen and newline commands.
   // Also test that we can write to all 4 lines.
   printf(lcd_putc, "\fThis is the 1st line");
   printf(lcd_putc, "\nNext is the 2nd line");
   printf(lcd_putc, "\nThis is the 3rd line");
   printf(lcd_putc, "\nFinally the 4th line");
   delay_ms(3000);

   // Test some additional characters.
   printf(lcd_putc, "\fABCDEFGHIJKLMNOPQRST");
   printf(lcd_putc, "\nabcdefghijklmnopqrst");
   printf(lcd_putc, "\n12345678901234567890");
   printf(lcd_putc, "\n!@#$^&*(){}[]:;<>?/=");
   delay_ms(3000);
   
      // Clear the LCD.
   printf(lcd_putc, "\f");
   delay_ms(500);

   // Test that lcd_gotoxy() works.  Go to each of
   // the four corners and put a number in each one,
   // in a clockwise direction, starting with the upper
   // left corner.
   lcd_gotoxy(4, 2);       
   printf(lcd_putc, "Put a number in");   
   lcd_gotoxy(4, 3);       
   printf(lcd_putc, "each corner.");   
   lcd_gotoxy(1, 1);       
   printf(lcd_putc, "1");   
   lcd_gotoxy(20, 1);       
   printf(lcd_putc, "2");   
   lcd_gotoxy(20, 4);       
   printf(lcd_putc, "3");   
   lcd_gotoxy(1, 4);       
   printf(lcd_putc, "4");   
   delay_ms(3000);
}
//end testscreen

void beep() {
   output_high(PIN_D0);
   delay_ms(100);
   output_low(PIN_D0);
}

void StartUpScreen() {
   beep();
   delay_ms(500); //clear the lcd

   printf(lcd_putc, "\f");   
   printf(lcd_putc, "\n   Welcome to The  ");
   printf(lcd_putc, "\n    Quizzor2000   ");

   
   delay_ms(3000);
   
   printf(lcd_putc, "\fRead an essay about\nthe revolution cycle\nand complete a quiz.");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }     
   }
   
      lcd_gotoxy(1, 2);       
      printf(lcd_putc, "\fProceeding to essay.");
     
      delay_ms(1000);
   
}
//end startupscreen

void EssayScreen() {

     char i;

   delay_ms(500); //clear the lcd
   
   printf(lcd_putc, "\f     Read the\nInformational Essay\nThen Press Any Btn");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
   
   
      printf(lcd_putc, "\f");
      lcd_gotoxy(1, 2);       
      printf(lcd_putc, "Proceeding to quiz..");
     
      delay_ms(1000);
     
      for (i=5;i==0;--i) {
         updateDisplay(i);
         beep();
         delay_ms(1000);
      }
   beep();
   beep();
}
//end essayscreen

void ResultScreen(int scr) {
   beep();
   if(scr >= 95){
      printf(lcd_putc, "\f\nYou've aced the quiz");
   } else if(scr < 95 && scr >= 75){
      printf(lcd_putc, "\f\nNot Bad Better\nLuck Next Time!");
   }else if(scr < 75){
      printf(lcd_putc, "\f\nYou can do better\nthan that!");
   }
}

void good() {
   printf(lcd_putc, "\f\n      Correct!");
   delay_ms(1500);
}

void bad() {
   printf(lcd_putc, "\f\n Sorry, incorrect..");
   delay_ms(1500);
}

void QuizScreen() {
   int score = 0;
   updateDisplay(score);
   
   printf(lcd_putc, "\f1. Thomas Jefferson\nMentioned ....\n Years in Between \n Each Revolution?");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }   
   printf(lcd_putc, "\f");
   printf(lcd_putc, "\nA.15");
   printf(lcd_putc, "\nB.20");
   printf(lcd_putc, "\nC.5");
   
      while(true){
         if(input(btn_B) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_A) == 0 || input(btn_C) == 0){
            beep();
            bad();
            break;
         }
      }
     
     printf(lcd_putc, "\f\n2. A Revolution is\nusually against ....");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }   
     
   printf(lcd_putc, "\f2.");
   printf(lcd_putc, "\nA.President");
   printf(lcd_putc, "\nB.Government");
   printf(lcd_putc, "\nC.All Of The Above");
   
      while(true){
         if(input(btn_C) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_A) == 0){
            beep();
            bad();
            break;
         }
      }
     
     printf(lcd_putc, "\f\n3.What causes the\ncycle of revolution");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
   printf(lcd_putc, "\f3.");
   printf(lcd_putc, "\nA.Unjust Government");
   printf(lcd_putc, "\nB.Other Revolutions");
   printf(lcd_putc, "\nC.Presidents");
   
      while(true){
         if(input(btn_A) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_C) == 0){
            beep();
            bad();
            break;
         }
      }
     
          printf(lcd_putc, "\f\n4.In Latin\nRevolution means");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f4.");
   printf(lcd_putc, "\nA.'redo'");
   printf(lcd_putc, "\nB.'turn around'");
   printf(lcd_putc, "\nC.'enormous power'");
   
      while(true){
         if(input(btn_B) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_A) == 0 || input(btn_C) == 0){
            beep();
            bad();
            break;
         }
      }
     
     printf(lcd_putc, "\f5.According to\nthe information,\nwhat might happen\nin Egypt?");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f5.");
   printf(lcd_putc, "\nA.We Live Happily");
   printf(lcd_putc, "\nB.Cycle of Rebels");
   printf(lcd_putc, "\nC.Endless Dictators");
   
      while(true){
         if(input(btn_B) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_A) == 0 || input(btn_C) == 0){
            beep();
            bad();
            break;
         }
      }
     
     printf(lcd_putc, "\f6.It is of human ...\nTo go by the rebel\n      Cycle.");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f6.");
   printf(lcd_putc, "\nA.origin 1");
   printf(lcd_putc, "\nB.rights 2");
   printf(lcd_putc, "\nC.nature 3");
   
      while(true){
         if(input(btn_C) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_A) == 0){
            beep();
            bad();
            break;
         }
      }
     
          printf(lcd_putc, "\f7.During Most\nRevolutions, What\nUsually Happens\n  With Power?");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f7.");
   printf(lcd_putc, "\nA.Sold");
   printf(lcd_putc, "\nB.Removed");
   printf(lcd_putc, "\nC.Changed");
   
      while(true){
         if(input(btn_C) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_A) == 0){
            beep();
            bad();
            break;
         }
      }
     
   printf(lcd_putc, "\f8.The Revolution\nCycle .... In The\n  Hunger Games");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f8.");
   printf(lcd_putc, "\nA.Changed");
   printf(lcd_putc, "\nB.Partially Occured");
   printf(lcd_putc, "\nC.Didn't Occur");
   
      while(true){
         if(input(btn_C) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_A) == 0){
            beep();
            bad();
            break;
         }
      }
     
        printf(lcd_putc, "\f9.How Can People\nStop The Rebellion\n     Cycle?");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f9.");
   printf(lcd_putc, "\nA.Changing thoughts");
   printf(lcd_putc, "\nB.Changing habits");
   printf(lcd_putc, "\nC.All of the Above");
   
      while(true){
         if(input(btn_C) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_B) == 0 || input(btn_A) == 0){
            beep();
            bad();
            break;
         }
      }
     
             printf(lcd_putc, "\f10.What is the\nusual reason for\na sequencial rebel?");
   
   while(true){
      if(input(btn_A) == 0 || input(btn_B) == 0 || input(btn_C) == 0) {
         beep();
         break;
      }   
   }
     
      printf(lcd_putc, "\f10.");
   printf(lcd_putc, "\nA.For Fun");
   printf(lcd_putc, "\nB.Clean up the past");
   printf(lcd_putc, "\nC.None of the Above");
   
      while(true){
         if(input(btn_B) == 0){
            beep();
            good();
            score += 10;
            updateDisplay(score);
            break;
         } else if(input(btn_A) == 0 || input(btn_C) == 0){
            beep();
            bad();
            break;
         }
      }
     
      ResultScreen(score);
}
//end quizscreen

void main() {
   
   output_low(LCD_RW);
   
   lcd_init(); //start the lcd
   delay_ms(1500);
   if(input(btn_A) == 0 && input(btn_B) == 0 && input(btn_C) == 0) {
     beep();
     beep();
     testScreen();
   }
   StartUpScreen();
   EssayScreen();
   QuizScreen();
   while(1);
   //While (true) {
   //       
   //}
}

/*
#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)

#include <Flex_LCD420.c>
#include <7segDisp.c>


int i;
void main() {

   output_low(LCD_RW);
   
   lcd_init();
   printf(lcd_putc, "\fHello World");
   delay_ms(1000);
   printf(lcd_putc, "\f\n     Welcome To");
   delay_ms(1000);
   printf(lcd_putc, "\n    Quizzor 2000");
   delay_ms(1000);
   updateDisplay(5);
   delay_ms(1000);
   updateDisplay(4);
   delay_ms(1000);
   updateDisplay(3);
   delay_ms(1000);
   updateDisplay(2);
   delay_ms(1000);
   updateDisplay(1);
   delay_ms(1000);
   printf(lcd_putc, "\f\n       Boom!");
   //delay_ms(5000);
   //for (i=10;i==0;i--) {
    //     updateDisplay(i);
    //     printf(lcd_putc, "\f");
    //     printf(lcd_putc, i);
    //     delay_ms(1000);
    //  }
   while(1);
}*/
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 6:02 pm     Reply with quote

I de-soldered the three buttons and connected them to pins B0, B1, and B2 (That way I can connect them to +5v without resistors) however they always read 1 in the program, which is a test one:

Code:

#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)

#include <Flex_LCD420.c>
#include <7segDisp.c>

#define btn_A PIN_B0
#define btn_B PIN_B1
#define btn_C PIN_B2

int i;
void main() {

   output_low(LCD_RW);
   
   lcd_init();
   printf(lcd_putc, "\fPress Any Button");
   while(1){
      if(input(btn_A) == 0 || input(btn_B) == 1 || input(btn_C) == 1) {
         break;
      }
   }
   printf(lcd_putc, "\fChecking Btns..A");
   while(1){
      if(input(btn_A) == 1) {
         break;
      }
   }
   printf(lcd_putc, "\fChecking Btns..B");
   while(1){
      if(input(btn_B) == 1) {
         break;
      }
   }
      printf(lcd_putc, "\fChecking Btns..C");
   while(1){
      if(input(btn_C) == 1) {
         break;
      }
   }
   printf(lcd_putc, "\f\n       Boom!");
   while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 6:31 pm     Reply with quote

I was unable to access the CCS website for the last 4 hours, at least.
But now it's up again.


Your program is way too complicated for checking a button. Try this one
instead. It reads btn_A once every second and displays the results on
the 2nd line of the LCD. It should display a '1' every second, and then
when you press and hold down the button, it should start to display 0's,
and when you release it, then it should displays 1's again.

Also notice that I have enabled PortB pull-ups. That's essential.
Code:

#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)

#include <Flex_LCD420.c>

#define btn_A PIN_B0
#define btn_B PIN_B1
#define btn_C PIN_B2


void main()
{
int8 result;
 
output_low(LCD_RW);
lcd_init();
port_b_pullups(TRUE);

printf(lcd_putc, "\fPress Any Button\n");

while(1)
  {
   result = input(btn_A);
   printf(lcd_putc, "%u", result);
   delay_ms(1000);
  }

}
seifpic



Joined: 11 Mar 2012
Posts: 45
Location: Egypt

View user's profile Send private message

PostPosted: Sun Jun 10, 2012 6:46 pm     Reply with quote

PCM programmer wrote:
I was unable to access the CCS website for the last 4 hours, at least.
But now it's up again.


I wasn't able to access it either.

PCM programmer wrote:

Your program is way too complicated for checking a button. Try this one
instead. It reads btn_A once every second and displays the results on
the 2nd line of the LCD. It should display a '1' every second, and then
when you press and hold down the button, it should start to display 0's,
and when you release it, then it should displays 1's again.

Also notice that I have enabled PortB pull-ups. That's essential.
Code:

#include <16f877a.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay (crystal=4000000)

#include <Flex_LCD420.c>

#define btn_A PIN_B0
#define btn_B PIN_B1
#define btn_C PIN_B2


void main()
{
int8 result;
 
output_low(LCD_RW);
lcd_init();
port_b_pullups(TRUE);

printf(lcd_putc, "\fPress Any Button\n");

while(1)
  {
   result = input(btn_A);
   printf(lcd_putc, "%u", result);
   delay_ms(1000);
  }

}


It keeps Outputting 1s, no zeros. This is how my switches are wired now:

Code:

                      ___  Switch A
To                   _|_|_
B0  -----------------o   o---------x
                      ___  Switch B|
To                   _|_|_         |
B1  -----------------o   o---------x
                      ___  Switch C|
To                   _|_|_         |
B2  -----------------o   o------ --x
                                   |
                                  +5v


Edit:

Finally! I connected the switches to ground and it outputs zeros and ones! Thanks so much for your help, now I just have to get the original program working...

Edit2:

God Bless you, I couldn't have done this project without your help! It works great!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group