#define THIS_IS_STACK_APPLICATION #include "stacktsk.h" #include "tick.h" #include "delay.h" #include "network.h" #include "barcode.h" #include "keyboard.h" #include "MyI2C.h" #include "xlcd.h" #include /* * This is used by other stack elements. * Main application must define this and initialize it with * proper values. */ APP_CONFIG AppConfig; BYTE myDHCPBindCount = 0; #if defined(STACK_USE_DHCP) extern BYTE DHCPBindCount; #else /* * If DHCP is not enabled, force DHCP update. */ BYTE DHCPBindCount = 1; #endif /* * Set configuration fuses for HITECH compiler. * For MCC18 compiler, separately linked config.asm file * will set the correct fuses. */ #if defined(HITECH_C18) __CONFIG(1, UNPROTECT & HS); __CONFIG(2, PWRTEN & BORDIS & WDTDIS); #endif /* * Private helper functions. * These may or may not be present in all applications. */ static void InitAppConfig(void); static void InitializeBoard(void); static void SetConfig(void); // Skal fjernes #define LCD_IC 0x74 void mylcd_write_byte(unsigned char data) { StartI2C(LCD_IC); WriteI2CByte( data ); StopI2C(); Delay10us(1); //I2C spec's siger min 4.7 uSec mellem stop og næste start } void main(void) { // Tick to blink SYSTEM led. static TICK t = 0; char i; unsigned char numbers[20]; unsigned long amount; unsigned char lcd_buffer[21]; short number_count = 0; short produkt_amount = 0; static bit hello = 0; short varetal = 1; TICK tick; TICK lastTick; TICK diffTicks; /* * Initialize any application specific hardware. */ InitializeBoard(); /* * Initialize all stack related components. * Following steps must be performed for all applications using * PICmicro TCP/IP Stack. */ TickInit(); /* * Initialize Stack and application related NV variables. */ InitAppConfig(); StackInit(); network_init(); barcode_init(); InitI2C(); XLCDInit(); /* * Once all items are initialized, go into infinite loop and let * stack items execute their tasks. * If application needs to perform its own task, it should be * done at the end of while loop. * Note that this is a "co-operative mult-tasking" mechanism * where every task performs its tasks (whether all in one shot * or part of it) and returns so that other tasks can do their * job. * If a task needs very long time to do its job, it must broken * down into smaller pieces so that other tasks can have CPU time. */ // Defines the IP add. on the server machine (rnode is defined in network.h) rnode.IPAddr.v[0] = 192; rnode.IPAddr.v[1] = 168; rnode.IPAddr.v[2] = 1; rnode.IPAddr.v[3] = 20; while(1) { char keyboard_entered; char network_error; /* * Blink SYSTEM LED every second. */ if ( TickGetDiff(TickGet(), t) >= TICK_SECOND/2 ) { t = TickGet(); LATA4 ^= 1; } /* * This task performs normal stack task including checking * for incoming packet, type of packet and calling * appropriate stack entity to process it. */ StackTask(); /* * For DHCP information, display how many times we have renewed the IP * configuration since last reset. */ //mylcd_write_byte(0b10100101); if( (barcode_is_ready() || keyboard_entered) && !hello){ network_send_hello(0x01); hello = 1; } if (barcode_is_ready()) { for (i=0;i< barcode_get_length(); i++) { global_network_char[i] = global_barcode_buffer[i]; global_network_charlen = barcode_get_length(); } barcode_reset(); network_send_scan_frame( varetal, global_network_charlen ); varetal = 1; /* XLCDClear(); XLCDGoto(1,0); for (i=0;i< barcode_get_length(); i++) { XLCDPut(global_barcode_buffer[i]); } */ } keyboard_entered = keyboard_read_safe(); if( keyboard_entered ) { switch( keyboard_entered ) { case 'A': network_send_calc_total(); XLCDClear(); XLCDGoto(0,0); for( i=0; iv[byteIndex++] = atoi(temp); temp = str; } else if ( v < '0' || v > '9' ) return FALSE; str++; } buffer->v[byteIndex] = atoi(temp); return (byteIndex == 3); } void XLCDDelay15ms(void) { DelayMs(15); } void XLCDDelay4ms(void) { DelayMs(4); } void XLCDDelay100us(void) { INTCON_GIEH = 0; Delay10us(1); INTCON_GIEH = 1; }