--- trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/16 09:24:33 92 +++ trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/28 08:59:24 108 @@ -1,103 +1,12 @@ -/********************************************************************* - * - * TFTP Client Demo App for Microchip TCP/IP Stack - * - ********************************************************************* - * FileName: TFTPcDemo.c - * Dependencies: tftpc.h - * stacktsk.h - * xlcd.h - * tick.h - * Processor: PIC18 - * Complier: MCC18 v1.00.50 or higher - * HITECH PICC-18 V8.10PL1 or higher - * Company: Microchip Technology, Inc. - * - * Software License Agreement - * - * The software supplied herewith by Microchip Technology Incorporated - * (the “Company”) for its PICmicro® Microcontroller is intended and - * supplied to you, the Company’s customer, for use solely and - * exclusively on Microchip PICmicro Microcontroller products. The - * software is owned by the Company and/or its supplier, and is - * protected under applicable copyright laws. All rights are reserved. - * Any use in violation of the foregoing restrictions may subject the - * user to criminal sanctions under applicable laws, as well as to - * civil liability for the breach of the terms and conditions of this - * license. - * - * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, - * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED - * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, - * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR - * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. - * - * Author Date Comment - *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Nilesh Rajbharti 8/7/03 Original (Rev 1.0) - * - * - * This demo application demonstartes Microchip TFTP client module usage - * See TFTPDemo(), TFTPWrite() and TFTPRead() for actual implementation. - * - * This application monitors RB5 switch. On first push it - * writes 'tftpwr.bin' file to server. tftpwr.bin file is made up of - * first 16KB of program memory. - * On second push, it reads 'tftprd.txt' file from server. - * - * Server IP address is set in "Board Setup" mode using Hyperterminal. - * - * It displays rotating '-' to indicate command in progress. - * 'Y' to indicate success - * 'N' for failure - * 'T' for timeout - * 'E' for error. - * - * - * If running this applicaton on PICDEM.net use - * HS Oscillator - * Debug disabled - * Low Voltage Disabled - * Watchdog timer disabled - ********************************************************************/ -/* - * Following define uniquely deines this file as main - * entry/application In whole project, there should only be one such - * definition and application file must define AppConfig variable as - * described below. - */ #define THIS_IS_STACK_APPLICATION #include "stacktsk.h" -#include "dhcp.h" -#include "xlcd.h" #include "tick.h" #include "delay.h" -#include "udp.h" -#include "arp.h" -#include "arptsk.h" - - -// All TFTP command statuts display will be done on first line of LCD. -#define TFTP_COMMAND_DISPLAY_LINE 0 - -// Result will be displayed at y = 15. -#define TFTP_COMMAND_RESULT_POSITION 15 - +#include "network.h" -#define STARTUP_MSG "G1_Build_0x00" +#include -ROM char StartupMsg[] = STARTUP_MSG; - -#if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) -ROM char DHCPMsg[] = "DHCP/Gleaning..."; -#endif - -ROM char SetupMsg[] = "Board Setup..."; - -// 1234567890123456 -ROM char blankLCDLine[] = " "; /* * This is used by other stack elements. @@ -134,19 +43,19 @@ */ static void InitAppConfig(void); static void InitializeBoard(void); -static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD); static void SetConfig(void); + + void main(void) { // Tick to blink SYSTEM led. static TICK t = 0; - UDP_SOCKET usock1; - NODE_INFO rnode; - char datagrams_to_send = 10; - char sock_open = 0; - char is_resolved = 0; + + TICK tick; + TICK lastTick; + TICK diffTicks; /* * Initialize any application specific hardware. @@ -166,24 +75,9 @@ InitAppConfig(); StackInit(); + + network_init(); -#if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING) - if ( AppConfig.Flags.bIsDHCPEnabled ) - { - XLCDGoto(1, 0); - XLCDPutROMString(DHCPMsg); - } - else - { - /* - * Force IP address display update. - */ - myDHCPBindCount = 1; -#if defined(STACK_USE_DHCP) - DHCPDisable(); -#endif - } -#endif /* @@ -200,21 +94,12 @@ */ - // Defines the IP add. on the server machine + // 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; - /*rnode.MACAddr.v[0] = 0x00; - rnode.MACAddr.v[1] = 0x16; - rnode.MACAddr.v[2] = 0x76; - rnode.MACAddr.v[3] = 0x9F; - rnode.MACAddr.v[4] = 0xFE; - rnode.MACAddr.v[5] = 0xDA;*/ - - - while(1) { /* @@ -238,138 +123,33 @@ * configuration since last reset. */ - if ( DHCPBindCount != myDHCPBindCount ) - { - DisplayIPValue(&AppConfig.MyIPAddr, TRUE); - myDHCPBindCount = DHCPBindCount; - - if ( AppConfig.Flags.bIsDHCPEnabled ) - { - XLCDGoto(1, 14); - if ( myDHCPBindCount < 0x0a ) - XLCDPut(myDHCPBindCount + '0'); - else - XLCDPut(myDHCPBindCount + 'A'); - } - } - - if (DHCPIsBound()) - { - RA3 =0; - if (sock_open == 0) - { - if (ARPIsTxReady()) - { - if (is_resolved == 0) - { - ARPResolve( &rnode.IPAddr); - is_resolved = 1; - } - else - { - if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr)) - //if (MyArp( &rnode)) - { - usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP - sock_open=1; - } - } - - - - } - } - - if (UDPIsPutReady(usock1) && datagrams_to_send>0) - { - UDPPut( rnode.MACAddr.v[0] ); - UDPPut( rnode.MACAddr.v[1] ); - UDPPut( rnode.MACAddr.v[2] ); - UDPPut( rnode.MACAddr.v[3] ); - UDPPut( rnode.MACAddr.v[4] ); - UDPPut( rnode.MACAddr.v[5] ); - UDPPut('D'); - UDPPut('a'); - UDPPut('w'); - UDPPut(0); - UDPFlush(); - datagrams_to_send--; - } - } + + network_send_hello( 0x01 ); + + strncpy(global_network_char, "12345678", 8); + network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 + + strncpy(global_network_char, "87654444", 8); + network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 + + network_send_calc_total(); + + network_send_cash_payed(50000); + + network_send_cancel_last(); + + network_send_cancel_all(); + + network_send_goodbye(); } } -#if defined(MCHP_C18) - #pragma interrupt HighISR save=section(".tmpdata") - void HighISR(void) -#elif defined(HITECH_C18) - #if defined(STACK_USE_SLIP) - extern void MACISR(void); - #endif - void interrupt HighISR(void) -#endif +void interrupt HighISR(void) { TickUpdate(); -/* -#if defined(STACK_USE_SLIP) - MACISR(); -#endif -*/ } -#if defined(MCHP_C18) -#pragma code highVector=0x08 -void HighVector (void) -{ - _asm goto HighISR _endasm -} -#pragma code /* return to default code section */ -#endif - -static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD) -{ - char IPDigit[8]; - if ( bToLCD ) - { - /* - * Erase second line. - */ - XLCDGoto(1, 0); - XLCDPutROMString(blankLCDLine); - - } - - /* - * Rewrite the second line. - */ - XLCDGoto(1, 0); - - itoa(IPVal->v[0], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[1], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[2], IPDigit); - if ( bToLCD ) - { - XLCDPutString(IPDigit); - XLCDPut('.'); - } - - itoa(IPVal->v[3], IPDigit); - if ( bToLCD ) - XLCDPutString(IPDigit); -} /********************************************************************* * Function: void InitializeBoard(void) @@ -398,7 +178,7 @@ /* * LCD is enabled using RA5. */ - PORTA_RA5 = 0; // Disable LCD. +// PORTA_RA5 = 0; // Disable LCD. /* * Turn off the LED's. @@ -412,10 +192,6 @@ */ INTCON2_RBPU = 0; - XLCDInit(); - XLCDGoto(0, 0); - XLCDPutROMString(StartupMsg); - T0CON = 0; INTCON_GIEH = 1; INTCON_GIEL = 1; @@ -499,21 +275,3 @@ return (byteIndex == 3); } - -void XLCDDelay15ms(void) -{ - DelayMs(15); -} -void XLCDDelay4ms(void) -{ - DelayMs(4); -} - -void XLCDDelay100us(void) -{ - INTCON_GIEH = 0; - Delay10us(1); - INTCON_GIEH = 1; -} - -