It looks quite comprehensive.
I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.
It looks quite comprehensive.
I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.
If that was true... ASM additions, substraction, bit shifting functions and few STATUS register bits wouldn't exist...(carry/Borrow, Z)
Last edited by mister_e; - 12th May 2007 at 23:35.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Last edited by T.Jackson; - 13th May 2007 at 06:47.
Trent, If your example was right i could agree with some part of it... programming method and code optimization is an endless story... i'm not going to argument on which is better, which is worst... it's not what the actual thread is about anyway.
100X ??? NAH, i don't think so. Depending the Value of I, few times maybe... but not 100 for sure. and * 2, is just a Byte shifting, one position to the left... not much... 1-2 cycle not much.
-----------------------------
Charudatt,
before going in sleep mode, make sure those PINs are set to input (with pull-up) and the others are set LOW and OUTPUT (or input but with pull-down resistor). Once you'll press a key, RB<7:4> should see the LOW signal... which should wake your PIC, then you call the keypad scan.
Last edited by mister_e; - 13th May 2007 at 09:11.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Huh? Lookups have their place (and I love them when needed) but to say PICs are not equipped for calculations is just plain silly.I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.
For all your projects (that you have posted), was time of the issue or code space? (answer = the latter). With your example equation, which one takes less code space? Which one is faster for larger I? (answer = calculation based approach).
orCode:' Calculation based equation A = 100/I +J*2 If I > 100 then A = J<<1 ELSE A = 100 FOR X = 1 to 100 A = A – I IF A < I then OUT NEXT X OUT: A = X+ J<<1 ENDIF
Code:' lookup based equation A = 100/I +J*2 IF I = 1 then A = 100+J<<1 If I = 2 then A = 50 +J<<1 If I = 3 then A = 33+J<<1 If I = 4 then A = 25+J<<1 ... ' (a bunch more if-thens) ... if I =100 then A = 1+J<<1 If I > 100 then A = J<<1
Paul Borgmeier
Salt Lake City, UT
USA
__________________
I know the Pull up Resistor attaches to Vss but where does it go else wise? Also... What happens to other test programs etc by its presence?
Paul
To port B.
As for the programs, what programs? Depends on what are the programs doing... Usually the port B with PU enabled, reads as all 1s.
Ioannis
I didn't say not equipped - I said not as well equipped. And, I'm more so referring to something that's more so "hard coded" over calculations. When I say hard coded I'm talking about something that's direct as in (a = 100) Vs (a = b x 10 / 2) No prizes for guessing which is faster and uses less resource.
Last edited by T.Jackson; - 23rd May 2007 at 09:28.
If a is hard coded to equal 100, then I would guess b and c would be hard coded too. If I understand you correctly this is what the PIC a good for. If this was all I had to do I good do it on paper once and would not have to bother with all of this programing and such. In my world variables change.
In you opinion, what should we all be using?
Dave
Always wear safety glasses while programming.
How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?) I really want to trigger the circuit with a minimum of time so I want the pullup fast so that my transistors (Nice NPN's for switching) with about 4.7 K ohms lead in resistance trigger off pretty much as fast as any current comes on the pin to signal it.
I will be pushing a signal in the switch of the NPN transistor so that there is some current to pull a MOSFET fast. I need some current to move like NOW.
In any case since I just cooked a $15 chip and an X1 Board , I really want to know some answers. (I just burned up some money) I need to know what voltage appears on the pins of the chip when we set for example a PORTA.2 =1. or PORTA.2 = 0 Is it on PORTA.1 = 1 a positive or negative voltage. It was logic testing that cooked this equipment.
All advice will be appreciated.
Well I got a cross of a posting that occurred between my post and an answer.
The issue of Pullups seems to be a feature of the pin to cause it to draw some current to make it pull down a few thousandths of an ampere so that the circuit stays logic stable. I would think that if I am driving a transistor as I am the obvious value to use is about 10K because the transistor will have a 4.7 K or so leading out of the logic pin into the transistor Emitter. Or does this 4.7 to Vss draw down enough power so that the transistor needs no other resistor on the emitter?
Generally a 5 VDC to emitter of a switching transistor with logic state high would take a 4.7 K ohm in the way of the signal feeding into the emitter (P of the NPN). If you take a 5 VDC state with a 10 K ohm to Vss and the positive voltage on the pins as high logic state then a 4.7 to the emitter should keep enough current to the transistor to open the gate so I am guessing based upon the previous answer that a 10 K ohm is in order (???)
When we change from an input drain state as in the keyboard to an output control state, I would suspect that we add a current to bring the pin near switch on state but just below in order to logically control things, Is this so?
Thanks
Last edited by CluckShot; - 18th June 2007 at 00:52. Reason: cross posting
Hi MisterE
Using with succes your keypadroutine on a 4x2 keypad
I was wondering if it would be possible to jump out the keypadroutine if no key is pressed
in order to handle the main loop
I need to receive some serial commands by HSERIN, but when a key is pressed
it should go to a label and then return to the main loop checking Hserin
Now it waits for a keypress
Thanks
T. Jackson & Mr. E,
Nice work to both of you regarding Matrix Keypads!
I have used Trents example with great success, I plan on trying out Mr. E's with a handheld Wireless panel/LCD I put together for work. I want to add a 4x4 matrix keypad to the front of the reciever case and upgrade my TXM/RSM LR LINX modules to the new LT tranciever type. I really think having the matrix keypad will expand (the crap out of) the types of commands I can send.....wall mounted reciever, robot, whatever....
Padawan-78
Hello,
Just an hour ago I tried to include Mr. E's Keypad.bas file in pbp folder and my local "pic_programs" folder. I DID rename the txt file and saved it to .BAS file.
Here is the code....
Won't compile....Code:INCLUDE "KeyPad.bas" myvar var byte start: @ READKEYPAD _myvar hserout ["Key=",dec myvar,13,10] 'LCDOUT 254,ROW1,"COMMAND", DEC MYVAR goto start
I keep getting lots of "opcode expected instead of....'kb_row','kb_col', 'debounce_delay' " errors. I did read the thread about the errors found when you don't save as a .BAS file but I must not be seeing something obvious, happens to me alot on this forum.
Mr. E could you lend a hand,
I am using version 2.50A & PM assembler
Padawan-78
I'm doing a temperature control system. Pretty new to PIC programming. I have managed to display temperature on the LCD using an LM35 sensor and a 16 x 2 lcd with a 16F873. I want to add on a 4 x4 matrix keypad so that i can set setpoints to switch a relay and a low warning buzzer I have no idea how to program for the above mentioned add-ons. Please could someone help me. below is my code which will obviously need additions and a scematic of my circuit is attached . Please could somebody help me with this!!
' Define LCD registers and bits
Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
dEFINE LCD_BITS 4
DEFINE LCD_LINES 2
adval var word ' Create adval to store result
temp var word ' Create temp to store result
temp1 var word ' Create temp1 to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
ADCON0 = %11000001 ' Configure and turn on A/D Module
Pause 100 ' Wait 0.1 second
loop: ADCON0.2 = 1 ' Start Conversion
AGAIN: Pause 1
If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished
adval.highbyte = ADRESH ' Move HIGH byte of result to adval
adval.lowbyte = ADRESL ' Move LOW byte of result to adval
Lcdout $fe, 1 ' Clear screen
temp=50*adval ' Conversion to Degrees
temp=temp/100
Lcdout "TEMP = ",DEC temp,$DF,"C" ' Display the value of temp
temp1 = temp*18 ' Conversion to Fahrenheit
temp1 = temp1+320
temp1 = temp1/10
lcdout $FE,$C0, "TEMP = ",dec temp1,$DF,"F" ' Display the value of temp
Pause 1000 ' Wait 1 second
Goto loop ' Do it forever
End
HI
ABOUT THE ROUTINE WRITTEN BY MR MISTER_E.
I NEED HELP HOW TO MAKE THE NUMBERS ARE IN SERIES EXAMPLES 12345566
AND THEN PRESS THE BUTTON # SEND VIA SERIAL A SEQUECIA.
Code:#CONFIG __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _WRT_OFF #ENDCONFIG DEFINE OSC 4 TRISA=%00000011 TRISB=%00000000 TRISC=%11111110 ADCON0=%11000000 ADCON1=%00000111 INCLUDE "KeyPad2.bas" ' ' Hardware connection ' =================== DEFINE KEYPAD_ROW 4 DEFINE KEYPAD_ROW_PORT PORTC DEFINE KEYPAD_ROW_BIT 0 DEFINE KEYPAD_COL 3 DEFINE KEYPAD_COL_PORT PORTC DEFINE KEYPAD_COL_BIT 4 DEFINE KEYPAD_DEBOUNCEMS 200 'debounce delay = 200 mSec define KEYPAD_AUTOREPEAT 1 'use auto-repeat ' LCD Display ' ----------- ' Adjust these to suit your chosen LCD pinout ' '----DEFINIR LCD-------------------------------------------------------------- DEFINE LCD_DREG PORTB ' LCD data port DEFINE LCD_DBIT 4 ' LCD data starting bit DEFINE LCD_RSREG PORTB ' LCD register select port DEFINE LCD_RSBIT 2 ' LCD register select bit DEFINE LCD_EREG PORTB ' LCD enable port DEFINE LCD_EBIT 3 ' LCD enable bit DEFINE LCD_BITS 4 ' LCD data bus size DEFINE LCD_LINES 2 ' Number lines on LCD DEFINE LCD_COMMANDUS 5000 ' Command delay time in us DEFINE LCD_DATAUS 50 ' Data delay time in us mykey VAR BYTE myvar var byte array var byte[5] index var byte i var byte word_v var word LCDOUT $FE,1, " FONTE DIGITAL " PAUSE 1000 LCDOUT $FE,1 ' ---------------------------------[Program Start]---------------------------------------------- start: @ READKEYPAD _myvar gosub lcddisp goto start lcddisp: LCDOUT $FE,$C0,DEC4 myvar pause 60 return end
Bookmarks