-- (c) William Welch 2005 -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; -- you must not claim that you wrote the original software. -- If you use this software in a product, an acknowledgment in -- the product documentation would be appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must -- not be misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source distribution. -- -- This license is commonly known as the zlib/libpng License. -- -- airdrop.jal william welch 10 jan 2005 -- picmicro i/o port and i/o pin assignments -- for edtp.com airdrop-p with 18LF8621. -- Note: these values are for the 18LF8621. Be sure to modify them if you -- are using a different chip. Otherwise, you may have problems with -- accidentally code-protecting your chip. pragma target fuses 0x00, 0 pragma target fuses 0x01, 0x22 pragma target fuses 0x02, 0x0F pragma target fuses 0x03, 0x0E pragma target fuses 0x04, 0x83 pragma target fuses 0x05, 0x83 pragma target fuses 0x06, 0x80 pragma target fuses 0x07, 0 pragma target fuses 0x08, 0x0F pragma target fuses 0x09, 0xC0 pragma target fuses 0x0A, 0x0F pragma target fuses 0x0B, 0xE0 pragma target fuses 0x0C, 0x0F pragma target fuses 0x0D, 0x40 pragma target fuses 0x0E, 0 pragma target fuses 0x0F, 0 -- The following pins will be "high" (+5V) -- -- cf-13 vcc -- cf-32 -ce2 -- cf-38 vcc -- The following pins will be "low" (gnd) -- -- cf-01 gnd -- cf-07 -cel -- cf-50 gnd -- definitions for extra I/O ports and pins on the 'F8621 var volatile byte PORTF at 0x0F85 var volatile byte PORTG at 0x0F86 var volatile byte PORTH at 0x0F87 var volatile byte TRISF at 0x0F97 var volatile byte TRISG at 0x0F98 var volatile byte TRISH at 0x0F99 var volatile byte TRISJ at 0x0F9A var volatile byte LATF at 0x0F8E var volatile byte LATG at 0x0F8F var volatile byte LATH at 0x0F90 var volatile byte LATJ at 0x0F91 -- **************** CF address bus and data bus ***************** var byte cfaddr_lo is PORTH var byte cfaddr_hi is PORTG var byte cf_data_dir is port_d_direction, cf_data is portd -- **************** control signals ***************** var bit cf_oe at LATF : 0 var bit cf_iord at LATF : 1 var bit cf_reg at LATF : 2 var bit cf_reset at LATF : 4 var bit cf_we at LATF : 6 var bit cf_iowr at LATF : 7 -- **************** status signals (inputs) ***************** var bit cf_ready at PORTF : 5 -- one-time init of the system procedure init_board is -- setup all the pins that connect to the CF socket CMCON = 7 ADCON1 = 0x0f TRISA = 0 LATA = 0xff TRISC = 0x80 TRISF = 0x20 LATF = 0xfb TRISG = 0 LATG = 0xf0 TRISH = 0 LATH = 0 TRISJ = 0xef LATJ = 0xff -- setup CF signals to a known state cf_oe = high cf_iord = high cf_reg = high cf_reset = low cf_we = high cf_iowr = high cfaddr_hi = 0 cfaddr_lo = 0 -- reset the CF card delay_1ms ( 100 ) cf_reset = high delay_1ms ( 100 ) cf_reset = low end procedure -- debugging LED, not essential procedure toggle_led is LATA = LATA ^ 1; end procedure -- hand-tune this routine for stable CF bus cycles -- a delay of about 2uS seems to work fine. procedure wait_delay is asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop asm nop end procedure -- read CF attribute memory function attr_rd ( byte in addr_hi , byte in addr_lo ) return byte is var byte v cfaddr_hi = addr_hi cfaddr_lo = addr_lo cf_we = high cf_reg = low cf_data_dir = all_input cf_oe = low wait_delay v = cf_data cf_oe = high cf_reg = high return v end function -- write CF attribute memory procedure attr_wr( byte in addr_hi , byte in addr_lo , byte in data ) is cfaddr_hi = addr_hi cfaddr_lo = addr_lo cf_oe = high cf_reg = low cf_data_dir = all_output cf_we = low cf_data = data wait_delay cf_we = high cf_reg = high cf_data_dir = all_input end procedure -- 8-bit read from CF I/O space -- note: we assume the I/O space will never need the upper address bits. function iord8 ( byte in addr_lo ) return byte is var byte v cfaddr_hi = 0 cfaddr_lo = addr_lo cf_iord = high cf_iowr = high cf_reg = high cf_data_dir = all_input cf_reg = low cf_iord = low wait_delay v = cf_data cf_iord = high cf_reg = high return v end function -- 8-bit read from CF I/O space -- note: we assume the I/O space will never need the upper address bits. procedure iowr8 ( byte in addr_lo , byte in data ) is cfaddr_hi = 0 cfaddr_lo = addr_lo cf_iord = high cf_iowr = high cf_reg = high cf_reg = low cf_data_dir = all_output cf_data = data cf_iowr = low wait_delay cf_iowr = high cf_reg = high cf_data_dir = all_input end procedure