![]() | ![]() | ![]() |
| | #1 |
|
This thread is a continuation of C18 related off topic posts in Junebug Help.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #2 |
|
In JPUG#1 Multiplexing Charlieplexed Displays masking was discussed in the context of charlieplexing. The text regarding masking is discussed in the section: setLatA(), setTrisA() on page 5. Although the article is specific to manipulating the Junebug's charlieplexed leds it should provide a good general explaination of how masking is used in relation to IO ports. I am open to suggestions. 3v0 EDIT: Added link to JPUG#1 as suggested by Pommie. See his (the next) post for the link to the JPUG index.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #3 |
| Last edited by Pommie; 25th June 2009 at 03:54 PM. | |
| |
| | #4 |
|
Atom did a real good tip and tricks pdf for the C18 it here http://atomsofttech.no-ip.info/tempd...TechC18_v8.pdf This would be a good one for MrDeb http://www.blueroomelectronics.com/J...2_June2008.pdf and if he reads this down load it and read page 6 Last edited by be80be; 25th June 2009 at 04:06 PM. | |
| |
| | #5 | ||
|
Moved this from the junebug thread: Quote:
and to make sure Im generalizing this properly from your example Code: TRISBbits.TRISB1=0; or TRISB&=0b11111101 Code: TRISAbits.TRISA0 = 1; Code: PORTBbits.PORTB0 = 1; (I'm just explaining this to see if i have it right) TRISB&=0b11111101 will only shut off pin 1 or anywhere you insert a 0. and if you wanted to set some high without effecting the others you would OR it with a line of 0's where you wanted no change, and a 1 where you wanted it to definitely come out high. so for setting port A pins 1 and 3 high would I type: Code: PORTA|=0b00001010; [end of moved post] Quote:
Last edited by Triode; 25th June 2009 at 04:03 PM. | |||
| |
| | #6 |
|
If anyone wants example code that runs on a Junebug then you may find this thread interesting. Mike. | |
| |
| | #7 |
|
Triode, LATA is short for latch A and is a way to write to the actual latch circuitry of port A. This is needed because when you set/clear a single bit, the processor reads the whole port, modifies one bit and writes it back. So if you do PORTA|=4, it will read/modify/write (RMW) portA. If a bit on port A that was previously set high is heavily loaded it may read back as a zero and result in that being unintentionally cleared. The latch register gets around this problem by keeping (and returning) a copy of the previously written value. I'm pretty sure that is a confusing explanation. For a better one google, pic rmw problem. Mike. | |
| |
| | #8 | ||
| Quote:
Code: #define LED_MASK 0xC1 Code: // LEDs on A0,A6,A7
// LED index 0 1 2 3 4 5
const byte valA[]={0x01,0x40,0x40,0x80,0x80,0x01};
const byte dirA[]={0x80,0x80,0x01,0x01,0x40,0x40};
Quote:
Because we are only interested in PORTA bits 0,6 and 7 we use the masking to not change the other bits (1,2,3,4,5). 3v0
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |||
| |
| | #9 |
|
LATAbit.LATA0 sort of thing is good to use if you only need to change one bit. To make your code more portable you might do Code: #define STATUS_LED LATAbits.LATA0 #define STATUS_LED_TRIS TRISAbits.TRISA0 Then in your code write STATUS_LED_TRIS = 0; // for output and STATUS_LED = 1; // to source a LED
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #10 |
|
Thanks. I think I have enough about swithing ports high and low to get my going now. Any good C18 tutorials on how to capture a PWM signal? Also, at some point I'm going to have to learn about having a pic generate multiple PWM signals for motor control, I know it can be done, but all the tutorials I see on generating PWM use wait commands in a single loop that would seem to get in the way of generating other pwm signals, or doing anything else for that matter. I know a few ways of timing several loops simultaniously on PC but they dont seem to apply on a PIC. Last edited by Triode; 25th June 2009 at 04:39 PM. | |
| |
| | #11 |
|
We have talked about generating multiple PWM signals here several times. To do it in software I use a timer interrupt, 100 interrupts per period. On the 0th interrupt it turns on all outputs with a duty cycle greater than zero. For the next 99 it checks to see which if any it should turn off. On the next it turns them all back on and starts over. 100 is handy because you can express the PWM duty cycle as percents. Choose whatever number of interrupts works for you application.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #12 |
|
That's funny looks like C18 would set it right when changing just a bit with just the Code: #define STATUS_LED PORTAbits.RA.0 Code: #define STATUS_LED LATAbits.LATA0 Last edited by be80be; 25th June 2009 at 05:34 PM. | |
| |
| | #13 | |
| Quote:
A question about the Latch command, when you change it that way, since its directly refering to the device, not the bit that controls it (as I understand it) is the bit still updated so that if you set LATAbits.LATA0 = 1 then read the status of PORTAbits.RA.0 it will also have changed? Are there any pitfalls or discrepencies here, or does it read just fine? | ||
| |
| | #14 | ||
|
Here you go have at the whole story in a nutshell Quote:
Quote:
Last edited by be80be; 25th June 2009 at 07:31 PM. | |||
| |
| | #15 |
|
Now that Burt has brought it up maybe we should say a word about port bit field names. In C18 some ports use names like PORTXbits.RX0 while others will have names like PORTXbits.PORTX0 If in doubt check the processor .h (ie: p18f1320.h) file to see what names are used or allowed. It helps if you understand what a union is. You can even add to or modify the definitions it you like. But I would not recommend it in most cases.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
|
| Tags |
| c18, questions |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| A few questions | erosennin | Feedback/Comments | 24 | 29th November 2007 12:08 AM |
| 2 questions | juan123 | Electronic Projects Design/Ideas/Reviews | 5 | 27th September 2007 03:46 AM |
| A few questions. | Marks256 | General Electronics Chat | 55 | 5th August 2006 11:49 PM |
| few questions | Victor Frankenstein | General Electronics Chat | 13 | 5th July 2005 07:29 PM |
| Questions? | Philipc | Electronic Projects Design/Ideas/Reviews | 4 | 7th August 2003 07:18 PM |