/* 877_15seg1.c * * Copyright (c) 2002, 2003 Bruce Kroeze * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * --------------------------------- * * Displays characters on a 15 seg led module * * Revisions: * 22 Dec 2002 - Initial Version * * Hardware: * 16F877 at 20Mhz * PCF8574P I2C IO Expander (IO1) * PCF8574P I2C IO Expander (IO2) * display connected with: * IO1 P0-P8: ABCDEFGH * IO2 P0-P7: IJKLMNO */ #include "defs_877.h" #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(CLOCK=20000000) #use fast_io(b) #include "15seg.h" #use rs232(baud=9600, PARITY=N, BITS=8, xmit=PIN_C7, rcv=PIN_C6) #use i2c(master, sda=PIN_C4, scl=PIN_C3, FORCE_HW) #DEFINE IO1 0b01000000 #DEFINE IO2 0b01000010 char curr; int16 work; void write_i2c_byte(int8 addr, int8 data) { i2c_start(); i2c_write(addr); i2c_write(data); i2c_stop(); } void display_segs(int16 ch) { write_i2c_byte(IO1, ch ^ 0xFF); write_i2c_byte(IO2, (ch >> 8) ^ 0xFF); } void print_ch(char ch) { work = get_15seg(ch); printf("Got val: 0x%LX\n\r", work); display_segs(work); } void main() { setup_psp(PSP_DISABLED); TRISB = 0; // all output TRISD = 0; PORTB = 0xFF; PORTD = 0xFF; printf("Ready to display.\n\r"); while (1) { curr = getch(); printf("%c = %X\n\r", curr, curr); print_ch(curr); } }