Sie sind auf Seite 1von 12

A Universal Advanced Keypad Library Printer-friendly version | Forums | FAQs |

Getting an input from a user may seem trivial, but in real word it will lead to resolve some problems like switch bounce, input correction, input validation, polling function in each major loop of the program, and so on... Here is a very convenient way to solve them : this interrupt-based keypad library will do it for you.

Page index :

Why another PIC Keypad LIBRARY ? Library functions Configuration Circuit example MikroC source code example Project download

Why another PIC Keypad LIBRARY ? There are already tons of keypad PIC libraries on the web, but I think this one will be the most universal and versatile, featuring : keypad up to 8x8 or buttons up to 8 fully configurable I/O : user defined ports in keypad mode row port and column port may be different user defined bits in port user defined rows and columns number user defined character lookup table user defined erase and enter keys works on interrupt : no polling necesary, no key lost auto debounce, delay is user defined switchable typematic (auto-repeat) mode at run time, rate is user defined switchable linear/circular buffer mode at run time input is available at any time in a string buffer maximum input size is user defined other functions : last key entered keypad status...

FORUMS A PIC16F84A Alarm Clock Microcontroll ers Project Printer-friendly version | Forums | FAQs | Examples NEW:: picoDetector : How to detect metal with a PIC picoBAT, an ultrasonic bat Here is a simple PIC16F84A alarm clock. detector with This page summarizes this discussion (in 3 components french) in my forum, where Samir (aka LCDscope, numerique1) requested for help to build a not a GLCD weekly alarm clock for his school. Many but a text thanks to him for his tests and patience. LCD This clock counts seconds, minutes, hours oscilloscope and day of the week. TouchClock : Time is displayed on 4 seven segment LED Design your displays, and is adjustable with three buttons own GLCD at start time (up, down, enter). Clock You can program the day of the week, hour, Coming Soon minute and duration of the alarms. : Ethernal The number of alarms are limited by ROM clock, a space only. digital SNTP The alarm is on the RA4 open collector clock with output of the PIC, and is repeated on a embedded decimal point of the display. web server Pico OSD, a For once, the program is in BASIC PIC video (mikroBasic) and I hope it will make a good superimposer start for beginners. PicOClock, a PIC Oscilloscope Clock A Universal Advanced Photo : credits to Samir who built Keypad this clock Library A First, the BASIC source code. PIC16F84A Alarm Clock Note that you can build it either for common cathod or common anode LED Binary File to display. C, Basic and

Pascal '*************************************************************** Converter *************** PIC16F877A ' PIC16F84A ALARM CLOCK Thermometer '*************************************************************** *************** with ' MCP9700A ' feel free to use this code at your own risks sensor ' Mysterious ' target : PIC16F84A, 16 Mhz crystal Opcodes in ' HS clock, no watchdog. ' PIC16 ' Author : Bruno Gavand, September 2007 Instruction ' see more details on http://www.micro-examples.com/ Set ! ' A Voice '*************************************************************** Controlled *************** LED Light program alarmClock Show PIC PAL ' Video Library ' if you are using COMMON CATHODE LED display, uncomment this The Secret definition. Functions of ' if you are using COMMON ANODE LED display, comment this definition. MikroC ' Ethernet Library for '#define CATHODE_COMMUNE ENC28J60 symbol LUNDI = 0 ' monday A Cheap symbol MARDI = 1 ' thuesday Ultrasonic symbol MERCREDI = 2 ' wednesday symbol JEUDI = 3 ' thursday Range Finder symbol VENDREDI = 4 ' friday A PIC16F819 symbol SAMEDI = 5 ' saturday DYMOCLOC symbol DIMANCHE = 6 ' sunday K symbol LMMJV = 7 ' from monday to friday included PIC16F84A MemoSound ' ' alarm definitions, to be changed on your needs Game ' EasyPic3 symbol NBALARM = 16 ' number of programmed alarms Programming Status LED const alarmTable as byte[NBALARM * 4] = ( EasyPic2 ' JOUR HEURE MINUTE DUREE (secondes, 59 with on-board maxi) ' DAY HOUR MINUTE DURATION (in seconds, Ethernet max is 59) Adapter LUNDI, 8, 30, 10, C, Pascal & LUNDI, 12, 30, 10, Basic to ASM LUNDI, 14, 00, 10, translator LUNDI, 16, 30, 10, MARDI, 8, 30, 10, Automatic MARDI, 12, 30, 10, LED display MARDI, 14, 00, 10, dimmer MARDI, 16, 30, 10, PIC PWM JEUDI, 8, 30, 10, Calculator & JEUDI, 12, 30, 10,

Code JEUDI, 14, 00, 10, Generator JEUDI, 16, 30, 10, VENDREDI, 8, 30, 10, Simple & VENDREDI, 12, 30, 10, Cheap VENDREDI, 14, 00, 10, Thermometer VENDREDI, 16, 30, 10 Multiple non) blocking delays with 1 dim maxcount as word ' number of TMR0 overflow per second timer as word ' RTC scaler DCF-77 PIC dim scaler dim jj as byte ' day of week, 0 is monday LED clock dim hh as byte ' hour Simple dim mn as byte ' min Frequency dim ss as byte ' sec Meter dim digiled as byte[4] ' 4 x 7 segment table as byte ' number of current digit to be Single-Tube dim digit displayed nixie clock dim dp as byte ' decimal point EasyPic2 dim key as byte ' key code programming dim alarm as byte ' alarm flag status LED PIC FAQs ' ' the ISR works as real time clock PIC .HEX ' Test Files sub procedure interrupt Free dim i as byte Download LED Blinking ' Example ' count time ' VR Stamp scaler = scaler + 1 development if scaler > maxcount kit by then mikroElektro scaler = 0 nika inc(ss) Sudoku if ss = 60 Solver then Online Shop ss = 0 Site & Web inc(mn) Search if mn = 60 Links then mn = 0 About the inc(hh) Author Did you find this site useful ? Please
Top of Form

_s-xclick -----BEGIN PKCS7

end if end if

if hh = 24 then hh = 0 inc(jj) if jj = 8 then jj = 1 end if end if

end if ' ' LED display to help ' www.micro- #ifdef CATHODE_COMMUNE PORTA = PORTA and $f0 examples.com TRISA = $0f key = PORTA If you need a TRISA = 0 coder or a PORTB = 0 freelance #else programmer, PORTA = PORTA or $0f TRISA = $0f submit your key = PORTA project to me key = not(key) TRISA = 0 Demandez PORTB = $ff Google de #endif traduire cette key = key and $07
Bottom of Form

page en franais

digit = digit + 1 if digit > 3 then digit = 0 i = $01 else i = $01 << digit end if #ifdef CATHODE_COMMUNE PORTB = digiled[digit] PORTA = PORTA or i #else PORTB = digiled[digit] PORTB = not(PORTB) PORTA = PORTA and not(i) #endif INTCON.T0IF = 0 end sub ' ' converts digit to 7 segment ' sub function intTo7seg(dim n as byte) as byte select case n case 0 result = $3F case 1 result = $06 case 2 result = $5B case 3 result = $4F case 4 result = $66 case 5 result = $6D case 6 result = $7D case 7 result = $07

case 8 case 9 end select end sub

result = $7F result = $6F

' ' select a value with keys ' value is pointed to by v, display char s as header, maximum value is max ' sub procedure setValue(dim v as ^byte, dim s as byte, dim max as byte) digiled[0] = s digiled[1] = 0 while 1 if key.0 then

inc(v^) if(v^ > max) then v^ = 0 end if

end if if key.1 then if(v^ = 0) then v^ = max else dec(v^) end if end if if key.2 then Delay_ms(50) while key.2 wend Delay_ms(50) scaler = 0 ss = 0 return

end if

digiled[2] = intTo7seg(v^ / 10) digiled[3] = intTo7seg(v^ mod 10) wend end sub ' ' program entry ' delay_ms(300)

main: dim i as byte ' ' init variables ' dp = 0 hh mn ss jj = = = = 0 0 0 0

maxcount = 15625 ' ' init I/O ' PORTA = %00010000 TRISA = %00000000 PORTB = 0 TRISB = $00 ' ' init interrupts ' INTCON = %10100000 OPTION_REG = %11011000 Delay_ms(50) ' ' clock adjustment ' setValue(@hh, 116, 23) setValue(@mn, 55, 59) setValue(@jj, 14, 6) ' ' forever loop ' while true if key then ' ' display day and seconds (what for ? don't remember !) ' digiled[0] = intTo7seg(jj) digiled[1] = 0 digiled[2] = intTo7seg(ss / 10) digiled[3] = intTo7seg(ss mod 10) else ' ' display hours and minutes '

if hh < 10 then digiled[0] digiled[1] else digiled[0] digiled[1] 10)

= 0 = intTo7seg(hh) = intTo7seg(hh / 10) = intTo7seg(hh mod

end if digiled[2] = intTo7seg(mn / 10) digiled[3] = intTo7seg(mn mod 10) end if

' ' blinks semicolon (or decimal point) ' if scaler > maxcount / 2 then dp.1 = 1 else dp.1 = 0 end if ' ' set decimal points ' digiled[0].7 digiled[1].7 digiled[2].7 digiled[3].7

= = = =

dp.0 dp.1 dp.2 dp.3

' ' check for alarm condition ' alarm = 0 for i = 0 to (NBALARM - 1) * 4 if ((alarmTable[i] = jj) or ((alarmTable[i] = LMMJV) and (jj < SAMEDI))) and (alarmTable[i + 1] = hh) and (alarmTable[i + 2] = mn) and (alarmTable[i + 3] > ss) then inc(alarm) end if next i if alarm then ' ' set alarm '

dp.3 = 1 PORTA.4 = 0

else ' ' clear alarm ' end if end. wend

dp.3 = 0 PORTA.4 = 1

Here is the circuit schematic (click on the picture to get a full sized image) :

All trademarks and registered trademarks are the property of their respective owners

Automatic RoomLight Controller Automatic School Timer AVR Development Board Baby Incubator Car Parking Monitoring System Cellphone Operated Robot Controller Area Network CAN Electronic Voting Machine Floor Cleaner GreenHouse Robot Industrial control Using Cellphone Pick And Place Robot Public Garden Management Combat Robot Submarine Robot Temperature Controlled Fan Time Based Device Controlling Level Computing & Storage Device Person counter & Pwrd detector Temperature & Light monitoring Rolling display using Matrix LEDs Home Security System Greenhouse Monitor & Control

Das könnte Ihnen auch gefallen