PIC16f877a 2x16 LCD + KEypad

Thread Starter

freigo

Joined Jan 9, 2011
2
PLEASE HELP ME!

I doing a simple calculator for my project using a 2x16 Lcd keypad and button, i got my circuit from combination of circuits in http://www.mikroe.com tutorials

and im using proteus to simulate it, Good thing is it works perfectly fine in simulation, BUT it Doesn't work on actual..it only displays BLOCK

here my code and diagram, please check it out for some problem

View attachment HOPE.zip

i check all my connection and it seems right,
i can't find the problem Please please help me

Tnx
 
Last edited:

spinnaker

Joined Oct 29, 2009
7,830
PLEASE HELP ME!

I doing a simple calculator for my project using a 2x16 Lcd keypad and button, i got my circuit from combination of circuits in http://www.mikroe.com tutorials

and im using proteus to simulate it, Good thing is it works perfectly fine in simulation, BUT it Doesn't work on actual..it only displays BLOCK

here my code and diagram, please check it out for some problem

View attachment 26334

i check all my connection and it seems right,
i can't find the problem Please please help me

Tnx

Don't post a zip file. Just post the code in line with the code block.

Be certain of your connection. Step through your code and verify eeach input on the LCD is being set as expected.

Check your timing on sending data to the LCD. Especially after power up. I put a 50-75 ms delay after power up and before trying to do anything with the LCD.

Check you "contrast" (v0 input) setting.
 

Thread Starter

freigo

Joined Jan 9, 2011
2
thanks for the reply. we've checked the connections and the code.. everything seems right because its doing fine with proteus

anyway here's the diagram and the code.




Rich (BB code):
program HOPE

dim text as char[20]
dim kp, cnt, operator_sign as byte
dim txt as string[5]
dim number, number_temp, number_temp2, save_number, save_number2  as word


main:
  TRISB = 0
  Keypad_Init(PORTD)                   ' PORTB is output
  Lcd_Init(PORTB)             ' Initialize LCD on PORTB
  Lcd_Cmd(Lcd_CURSOR_OFF)     ' Turn off cursor
  Lcd_Cmd(LCD_CLEAR)
  text = "-----COE 5A------"
  Lcd_Out(1, 1, text)         ' Print text at LCD
  delay_ms(5000)
  Lcd_Cmd(LCD_CLEAR)


while TRUE
    kp = 0

    '--- Wait for key to be pressed
    while kp = 0
   '--- un-comment one of the keypad reading functions
      kp = Keypad_Released

      if (Button(PORTC,7,1,1)) then ' If PORTB.7 is pressed Plus
      kp = 16
      end if

      if (Button(PORTC,6,1,1)) then ' If PORTB.7 is pressed Minus
      kp = 17
      end if

      if (Button(PORTC,5,1,1)) then ' If PORTB.7 is pressed multiply
      kp = 18
      end if

      if (Button(PORTC,4,1,1)) then ' If PORTB.7 is pressed divide
      kp = 19
      end if

      if (Button(PORTC,3,1,1)) then ' If PORTB.7 is pressed equals
      kp = 20
      end if

      if (Button(PORTC,2,1,1)) then ' If PORTB.7 is pressed equals
      kp = 21
      end if

      if (Button(PORTC,1,1,1)) then ' If PORTB.7 is pressed equals
      kp = 22
      end if

      if (Button(PORTC,0,1,1)) then ' If PORTB.7 is pressed equals
      kp = 23
      end if
    wend



  select case kp     ' Prepare value for output
    case 1 number = 1
    case 2 number = 2
    case 3 number = 3
    case 5 number = 4
    case 6 number = 5
    case 7 number = 6
    case 9 number = 7
    case 10 number = 8
    case 11 number = 9
    case 13 save_number = number_temp
            Lcd_Cmd(LCD_CLEAR)
            cnt = 4
    case 14 number = 0
    case 15 WordToStr(save_number, txt)
            number_temp = save_number
            Lcd_Out(1, 12, txt)
            cnt = 4
    case 16 Lcd_Cmd(LCD_CLEAR)

            operator_sign = 1 '--------------sign operator

            Lcd_Out(2, 1, "+")
            number_temp2 = number_temp
            WordToStr(number_temp2, txt)
            Lcd_Out(2, 12, txt)


            cnt = 4
    case 17 Lcd_Cmd(LCD_CLEAR)

            operator_sign = 2 '--------------sign operator

            Lcd_Out(2, 1, "-")
            number_temp2 = number_temp
            WordToStr(number_temp2, txt)
            Lcd_Out(2, 12, txt)
            cnt = 4
    case 18 Lcd_Cmd(LCD_CLEAR)

            operator_sign = 3 '--------------sign operator

            Lcd_Out(2, 1, "*")
            number_temp2 = number_temp
            WordToStr(number_temp2, txt)
            Lcd_Out(2, 12, txt)
            cnt = 4
    case 19 Lcd_Cmd(LCD_CLEAR)

            operator_sign = 4 '--------------sign operator

            Lcd_Out(2, 1, "/")
            number_temp2 = number_temp
            WordToStr(number_temp2, txt)
            Lcd_Out(2, 12, txt)
            cnt = 4
    case 20
            if operator_sign = 1 then
               number_temp = number_temp2 + number_temp
               number_temp2 = 0
            end if

            if operator_sign = 2 then
               number_temp = number_temp2 - number_temp
               number_temp2 = 0
            end if

            if operator_sign = 3 then
               number_temp = number_temp2 * number_temp
               number_temp2 = 0
            end if

            if operator_sign = 4 then
               number_temp = number_temp2 / number_temp
               number_temp2 = 0
            end if

            Lcd_Cmd(LCD_CLEAR)
            WordToStr(number_temp, txt)
            Lcd_Out(1, 12, txt)
            operator_sign = 0
            cnt = 4
    case 21 save_number2 = number_temp
            Lcd_Cmd(LCD_CLEAR)
            cnt = 4

    case 22 WordToStr(save_number2, txt)
            number_temp = save_number2
            Lcd_Out(1, 12, txt)
            cnt = 4
    case 23 number_temp = 0
            number_temp2 = 0
            save_number = 0
            save_number2 = 0
            Lcd_Cmd(LCD_CLEAR)
            cnt = 4

    end select

   inc(cnt)

select case cnt
  case 1 number_temp = number
         WordToStr(number_temp, txt)
         Lcd_Out(1, 12, txt)

  case 2 number_temp = (number_temp * 10) + number
         WordToStr(number_temp, txt)
         Lcd_Out(1, 12, txt)

  case 3 number_temp =  (number_temp * 10) + number
         WordToStr(number_temp, txt)
         Lcd_Out(1, 12, txt)

  case 4 Lcd_Cmd(Lcd_Clear)
         number_temp = number
         WordToStr(number_temp, txt)
         Lcd_Out(1, 12, txt)
         cnt = 1
  case 5 cnt = 0

end select


  wend


  
  
end.
 

spinnaker

Joined Oct 29, 2009
7,830
How did you check the connections? Did you just look at them? Or did you single step through your code and put a meter on each pin of the LCD to be sure it is setting what it should be setting.

How do you know anything is even running?


Did you put in a startup delay?

Proteus is not the real world.



Keep your code simple at first. Forget about all that other code that processes the key press. Just write some simple code to display "Hello World" to the LCD.

I do not see an pot for your contrast. The voltage on VEE might be too high.


What are you expecting that 10K to do near the LCD ?

R2 is wired wrong. It should be just like the other switches.
 

thatoneguy

Joined Feb 19, 2009
6,359
Have you posted your questions on the mikroe forums?

It may be an issue with the way the compiler interprets some lines.

Otherwise, be sure you are using real models for all elements in Proteus, rather than "Ideal" switches, capacitors, resistors, etc.
 
Top