Menu

2-wire LCD, pushbuttons and speaker/buzzer 74LS164

Theo
2014-10-15
2014-10-15
  • Theo

    Theo - 2014-10-15

    Based on the 2-wire lcd diagram from Myke Predko with mods(74ls164) from Mike McLaren (See link); some functions for the using off push buttons or switches and a speaker/buzzer, see the diagram.
    Very useful for those who would like to play with microcontrollers with less pins.

    The variable Button gets the value of 1 to 15; pushing button A = 1, B = 2, C = 4, D = 8.
    By pushing 2 or more buttons at the same time you will get the sum of those buttons.

    To use the simple speaker or buzzer: it needs to be activated every time by the function BuzzerOn, followed by Tone YY,ZZ

    http://www.electro-tech-online.com/threads/k8lh-breadboard-buddy-lcd-interface.92030


    #chip mega8,8

    'Use LCD in 2 pin mode with 74LS164 / 74HC164
    #define LCD_IO 2
    #define LCD_DB PORTC.0 ; databit
    #define LCD_CB PORTC.1 ; clockbit
    #define LCD_NO_RW

    #define SWX PORTC.2 ; input pin from pushbuttons (A,B,C,D)
    #define Led PORTC.5 ; output pin for led
    #define SoundOut PORTC.0 ; output pin for tone

    dir SWX in ; set port as input

    BuzzerOn
    tone 440,50 ; Beep
    tone 660,50
    tone 880,50
    tone 1350,100

    do
    PushButton
    locate 0,0
    print "Button= ": print Button:print " "
    pulseout Led, 1 Ms ; if active: program is running
    loop

    ; ---------------------- Functions -----------------------
    function PushButton
    ClockXXTimes(8) ; clock in 8 times zero for clearing shiftreg
    ClockIn1 ; clock in a 1 to activate pin 3 (74LS164)
    button=0:GPVar=1
    repeat 4 ; clock 4 times to activate resp. pin 4, 5, 6 (74LS164)
    if SWX then
    wait 10 mS ; debounce switches/buttons
    end if
    if SWX then ; check for A,B,C and/or D button(s)
    button = button OR GPVar ; set 1 bit only, so pushing two or more buttons at
    end if ; the same time will be shown in the variable button
    rotate GPVar left ; shift bit to the left (1,2,4,8)
    set LCD_CB on:set LCD_CB off ; clock 1 time
    end repeat
    ClockXXTimes(3) ; clear shiftreg
    end function

    function ClockXXTimes(in GPVar) ; clock in XX times zero
    set LCD_DB off
    for index = 1 to GPVar
    set LCD_CB on:set LCD_CB off
    next
    end function

    function ClockIn1 ; clock in one
    set LCD_DB on:set LCD_CB on:set LCD_CB off:set LCD_DB off
    end function

    function BuzzerOn
    ClockXXTimes(8) ; clock in 8 times zero for clearing shiftreg
    ClockIn1 ; clock in one and
    ClockXXTimes(6) ; clock in 6 times zero to activate pin 12 (74ls164)
    end function

     

    Last edit: Theo 2014-10-15
  • Theo

    Theo - 2014-10-15

    Diagram

     
  • Anobium

    Anobium - 2014-10-15

    Nice job! And, great documentation.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.