Hi Matt, Please see "18f4550_pintools.jal", it's derived from jaluino's sample, tested OK. Let me know if you have any problems.
Cheers, Seb 2010/1/25 Sebastien Lelong <[email protected]> > You can try this one from jaluino: > > > http://code.google.com/p/jaluino/source/browse/trunk/samples/crumboard_pintools.jal > > I'm about to "jallibize" it, and a 18f4550 sample soon. > > > Cheers, > Seb > > 2010/1/24 mattschinkel <[email protected]> > > Is there a sample I can try? >> >> Matt. >> >> On Jan 24, 3:02 pm, [email protected] wrote: >> > Revision: 1619 >> > Author: sebastien.lelong >> > Date: Sun Jan 24 12:01:39 2010 >> > Log: beta pintools library, tested on jaluino, but not with all pins... >> http://code.google.com/p/jallib/source/detail?r=1619 >> > >> > Added: >> > /trunk/include/jal/pintools.jal >> > >> > ======================================= >> > --- /dev/null >> > +++ /trunk/include/jal/pintools.jal Sun Jan 24 12:01:39 2010 >> > @@ -0,0 +1,250 @@ >> > +-- Title: utility functions and procedures to manipulate pins (level, >> > mode, etc...) >> > +-- Author: Sebastien Lelong, Copyright (C) 2009, all rights reserved. >> > +-- Adapted-by: >> > +-- Compiler: 2.4m >> > +-- >> > +-- This file is part of jallib (http://jallib.googlecode.com) >> > +-- Released under the ZLIB license >> > (http://www.opensource.org/licenses/zlib-license.html) >> > +-- >> > +-- Description: This library provides a set of utility functions and >> > procedures >> > +-- to help users manipulating pins. For instance, you can dynamically >> > access pins >> > +-- using a specific mapping (RA0 is #0, RB1 is #2, etc...) and act on >> > levels, mode, >> > +-- directions, etc... >> > +-- -- >> > +-- Using this library requires that array "pintools_map" is first >> defined. >> > This array >> > +-- is composed by elements going by two: >> > +-- * the first element corresponds to the port letter ("A", "B", ...) >> > +-- * the second element corresponds to the pin number in this port (0, >> 1, >> > 2, ...) >> > +-- Pins are then accessed according to the index in this array >> (starting >> > with 0) >> > +-- Ex: const byte pintools_map [] = {"A","1", "B","1", "D","3} >> > +-- This 6 elements (2x3) array specifies that: >> > +-- * pin #0 corresponds to pin_A1 >> > +-- * pin #1 corresponds to pin_B1 >> > +-- * pin #2 corresponds to pin_D3 >> > +-- >> > +-- Notes: this library hasn't been fully tested, this is still BETA... >> > +-- >> > + >> > + >> > +-- Access pin by number and set its level (low/high) >> > +procedure pintools_set_level(byte in pinnum, bit in level) is >> > + var byte portmapletter = pintools_map[pinnum*2] >> > + var byte pinmapnum = pintools_map[pinnum*2+1] >> > + >> > + procedure _process_porta() is >> > + if defined(PORTA) == true then >> > + if level == high then >> > + PORTA = PORTA | (1 << pinmapnum) >> > + else >> > + PORTA = PORTA & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portb() is >> > + if defined(PORTB) == true then >> > + if level == high then >> > + PORTB = PORTB | (1 << pinmapnum) >> > + else >> > + PORTB = PORTB & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portc() is >> > + if defined(PORTC) == true then >> > + if level == high then >> > + PORTC = PORTC | (1 << pinmapnum) >> > + else >> > + PORTC = PORTC & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portd() is >> > + if defined(PORTD) == true then >> > + if level == high then >> > + PORTD = PORTD | (1 << pinmapnum) >> > + else >> > + PORTD = PORTD & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_porte() is >> > + if defined(PORTE) == true then >> > + if level == high then >> > + PORTE = PORTE | (1 << pinmapnum) >> > + else >> > + PORTE = PORTE & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portf() is >> > + if defined(PORTF) == true then >> > + if level == high then >> > + PORTF = PORTF | (1 << pinmapnum) >> > + else >> > + PORTF = PORTF & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portg() is >> > + if defined(PORTG) == true then >> > + if level == high then >> > + PORTG = PORTG | (1 << pinmapnum) >> > + else >> > + PORTG = PORTG & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_porth() is >> > + if defined(PORTH) == true then >> > + if level == high then >> > + PORTH = PORTH | (1 << pinmapnum) >> > + else >> > + PORTH = PORTH & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_portj() is >> > + if defined(PORTJ) == true then >> > + if level == high then >> > + PORTJ = PORTJ | (1 << pinmapnum) >> > + else >> > + PORTJ = PORTJ & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + -- because we can't refer to port name just as we can't refer to pin >> >> > since >> > + -- these are pseudo-variable, we need to switch over different >> cases... >> > + -- Note: there's no such PORTI in PIC.... >> > + case portmapletter of >> > + "A" : _process_porta() >> > + "B" : _process_portb() >> > + "C" : _process_portc() >> > + "D" : _process_portd() >> > + "E" : _process_porte() >> > + "F" : _process_portf() >> > + "G" : _process_portg() >> > + "H" : _process_porth() >> > + "J" : _process_portj() >> > + end case >> > + >> > +end procedure >> > + >> > + >> > +-- Access pin by number and set its direction (low/high) >> > +procedure pintools_set_direction(byte in pinnum, bit in direction) is >> > + var byte portmapletter = pintools_map[pinnum*2] >> > + var byte pinmapnum = pintools_map[pinnum*2+1] >> > + >> > + procedure _process_trisa() is >> > + if defined(TRISA) == true then >> > + if direction == input then >> > + TRISA = TRISA | (1 << pinmapnum) >> > + else >> > + TRISA = TRISA & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisb() is >> > + if defined(TRISB) == true then >> > + if direction == input then >> > + TRISB = TRISB | (1 << pinmapnum) >> > + else >> > + TRISB = TRISB & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisc() is >> > + if defined(TRISC) == true then >> > + if direction == input then >> > + TRISC = TRISC | (1 << pinmapnum) >> > + else >> > + TRISC = TRISC & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisd() is >> > + if defined(TRISD) == true then >> > + if direction == input then >> > + TRISD = TRISD | (1 << pinmapnum) >> > + else >> > + TRISD = TRISD & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trise() is >> > + if defined(TRISE) == true then >> > + if direction == input then >> > + TRISE = TRISE | (1 << pinmapnum) >> > + else >> > + TRISE = TRISE & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisf() is >> > + if defined(TRISF) == true then >> > + if direction == input then >> > + TRISF = TRISF | (1 << pinmapnum) >> > + else >> > + TRISF = TRISF & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisg() is >> > + if defined(TRISG) == true then >> > + if direction == input then >> > + TRISG = TRISG | (1 << pinmapnum) >> > + else >> > + TRISG = TRISG & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trish() is >> > + if defined(TRISH) == true then >> > + if direction == input then >> > + TRISH = TRISH | (1 << pinmapnum) >> > + else >> > + TRISH = TRISH & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + procedure _process_trisj() is >> > + if defined(TRISJ) == true then >> > + if direction == input then >> > + TRISJ = TRISJ | (1 << pinmapnum) >> > + else >> > + TRISJ = TRISJ & (0b_1111_1111 ^ (1 << pinmapnum)) >> > + end if >> > + end if >> > + end procedure >> > + >> > + >> > + case portmapletter of >> > + "A" : _process_trisa() >> > + "B" : _process_trisb() >> > + "C" : _process_trisc() >> > + "D" : _process_trisd() >> > + "E" : _process_trise() >> > + "F" : _process_trisf() >> > + "G" : _process_trisg() >> > + "H" : _process_trish() >> > + "J" : _process_trisj() >> > + end case >> > +end procedure >> > + >> >> -- >> You received this message because you are subscribed to the Google Groups >> "jallib" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<jallib%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/jallib?hl=en. >> >> > > > -- > Sébastien Lelong > http://www.sirloon.net > http://sirbot.org > -- Sébastien Lelong http://www.sirloon.net http://sirbot.org -- You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
