/[H8]/trunk/PIC/Demo trimmet/TFTPcDemo.c
ViewVC logotype

Diff of /trunk/PIC/Demo trimmet/TFTPcDemo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 91 by hedin, Tue May 8 09:37:15 2007 UTC revision 113 by hedin, Mon May 28 16:28:28 2007 UTC
# Line 1  Line 1 
 /*********************************************************************  
  *  
  *                  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.  
  */  
1  #define THIS_IS_STACK_APPLICATION  #define THIS_IS_STACK_APPLICATION
2    
3  #include "stacktsk.h"  #include "stacktsk.h"
 #include "dhcp.h"  
 #include "xlcd.h"  
4  #include "tick.h"  #include "tick.h"
5  #include "delay.h"  #include "delay.h"
6  #include "udp.h"  #include "network.h"
7  #include "arp.h"  #include "barcode.h"
8  #include "arptsk.h"  #include "keyboard.h"
9    #include "MyI2C.h"
10    #include "xlcd.h"
11  // All TFTP command statuts display will be done on first line of LCD.  #include <string.h>
 #define TFTP_COMMAND_DISPLAY_LINE       0  
   
 // Result will be displayed at y = 15.  
 #define TFTP_COMMAND_RESULT_POSITION    15  
   
   
 #define STARTUP_MSG "G1_Build_0x00"  
   
 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[] = "                ";  
12    
13  /*  /*
14   * This is used by other stack elements.   * This is used by other stack elements.
# Line 134  __CONFIG(2, PWRTEN & BORDIS & WDTDIS); Line 45  __CONFIG(2, PWRTEN & BORDIS & WDTDIS);
45   */   */
46  static void InitAppConfig(void);  static void InitAppConfig(void);
47  static void InitializeBoard(void);  static void InitializeBoard(void);
 static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD);  
48  static void SetConfig(void);  static void SetConfig(void);
49    
50    // Skal fjernes
51    #define LCD_IC 0x74
52    void mylcd_write_byte(unsigned char data)
53    {
54            StartI2C(LCD_IC);
55            WriteI2CByte( data );
56            StopI2C();
57            Delay10us(1); //I2C spec's siger min 4.7 uSec mellem stop og næste start
58    }
59    
60    
61    
62  void main(void)  void main(void)
63  {  {
64      // Tick to blink SYSTEM led.      // Tick to blink SYSTEM led.
65      static TICK t = 0;      static TICK t = 0;
66      UDP_SOCKET usock1;      char i;
67      NODE_INFO rnode;      unsigned char numbers[20];
68      char sock_open = 0;      unsigned long amount;
69      char is_resolved = 0;      unsigned char lcd_buffer[21];
70            short number_count = 0;
71            short produkt_amount = 0;
72            static bit hello = 0;
73            short varetal = 1;
74                    
75        TICK tick;
76        TICK lastTick;
77            TICK diffTicks;
78    
79      /*      /*
80       * Initialize any application specific hardware.       * Initialize any application specific hardware.
# Line 165  void main(void) Line 94  void main(void)
94      InitAppConfig();      InitAppConfig();
95    
96      StackInit();      StackInit();
97        
98  #if defined(STACK_USE_DHCP) || defined(STACK_USE_IP_GLEANING)      network_init();
99      if ( AppConfig.Flags.bIsDHCPEnabled )      barcode_init();
100      {      InitI2C();
101          XLCDGoto(1, 0);      XLCDInit();
102          XLCDPutROMString(DHCPMsg);          
     }  
     else  
     {  
         /*  
          * Force IP address display update.  
          */  
         myDHCPBindCount = 1;  
 #if defined(STACK_USE_DHCP)  
         DHCPDisable();  
 #endif  
     }  
 #endif  
103    
104    
105      /*      /*
# Line 199  void main(void) Line 116  void main(void)
116       */       */
117            
118    
119          // Defines the IP add. on the server machine          // Defines the IP add. on the server machine (rnode is defined in network.h)
120          rnode.IPAddr.v[0] = 192;          rnode.IPAddr.v[0] = 192;
121          rnode.IPAddr.v[1] = 168;          rnode.IPAddr.v[1] = 168;
122          rnode.IPAddr.v[2] = 1;          rnode.IPAddr.v[2] = 1;
123          rnode.IPAddr.v[3] = 20;          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;*/  
           
           
124    
       
125      while(1)      while(1)
126      {      {
127                char keyboard_entered;
128                char network_error;
129    
130    
131          /*          /*
132           * Blink SYSTEM LED every second.           * Blink SYSTEM LED every second.
133           */           */
# Line 236  void main(void) Line 148  void main(void)
148           * For DHCP information, display how many times we have renewed the IP           * For DHCP information, display how many times we have renewed the IP
149           * configuration since last reset.           * configuration since last reset.
150           */           */
           
         if ( DHCPBindCount != myDHCPBindCount )  
         {  
             DisplayIPValue(&AppConfig.MyIPAddr, TRUE);  
             myDHCPBindCount = DHCPBindCount;  
151    
152              if ( AppConfig.Flags.bIsDHCPEnabled )                          //mylcd_write_byte(0b10100101);
             {  
                 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))  
                                         {  
                                                 usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP  
                                                 sock_open=1;  
                                         }  
                                 }  
   
   
                                           
                         }  
                 }  
                   
                 if (UDPIsPutReady(usock1))  
                 {  
                         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();  
                 }  
         }  
     }  
 }  
153    
154  #if defined(MCHP_C18)                          if( (barcode_is_ready() || keyboard_entered) && !hello){
155      #pragma interrupt HighISR save=section(".tmpdata")                                  network_send_hello(0x01);
156      void HighISR(void)                                  hello = 1;
157  #elif defined(HITECH_C18)                          }
158      #if defined(STACK_USE_SLIP)                          if (barcode_is_ready())
159          extern void MACISR(void);                          {
160      #endif                                  for (i=0;i< barcode_get_length(); i++)
161      void interrupt HighISR(void)                                  {
162  #endif                                          global_network_char[i] = global_barcode_buffer[i];
163  {                                          global_network_charlen = barcode_get_length();
164      TickUpdate();                                  }
165                                    barcode_reset();
166                                    network_send_scan_frame( varetal, global_network_charlen );
167                                    varetal = 1;
168  /*  /*
169  #if defined(STACK_USE_SLIP)                                  XLCDClear();
170      MACISR();                                  XLCDGoto(1,0);
171  #endif                                  for (i=0;i< barcode_get_length(); i++)
172                                    {
173                                            XLCDPut(global_barcode_buffer[i]);
174                                    }
175  */  */
176  }                          }
177                            
178                            keyboard_entered = keyboard_read_safe();
179                            if( keyboard_entered )
180                            {
181                                    switch( keyboard_entered )
182                                    {
183                                            case 'A':
184                                            network_send_calc_total();
185                                            XLCDClear();
186                                            XLCDGoto(0,0);
187                                            for( i=0; i<global_network_charlen; i++ )
188                                            {
189                                                    XLCDPut(global_network_char[i]);
190                                            }
191                                            break;
192                                            
193                                            case 'B':
194                                            numbers[number_count] = 0; //nulterminering inden brug af atol
195                                            amount = atol(numbers);
196                                            number_count = 0;
197                                            
198                                            network_send_cash_payed(amount);
199                                            network_send_goodbye();
200                                            hello = 0;
201                                            
202                                            sprintf(lcd_buffer,"%5d", amount);
203                                            XLCDGoto(0,0);
204                                            XLCDPutString(lcd_buffer);
205                                            break;
206                                            
207                                            case 'C':
208                                            network_send_cancel_last();
209                                            break;
210                                            
211                                            case 'D':
212                                            network_send_cancel_all();              
213                                            network_send_goodbye();
214                                            hello = 0;                      
215                                            break;
216                                            
217                                            case 'E':
218                                            for( i=0; i<number_count;i++ )
219                                            {
220                                                    global_network_char[i] = numbers[i];
221                                            }
222                                            network_send_scan_frame( varetal, number_count );
223                                            varetal = 1;
224                                            number_count = 0;
225                                            break;
226                                            
227                                            case 'F':
228                                            numbers[number_count] = 0; //nulterminering inden brug af atol
229                                            varetal = atol(numbers);
230                                            number_count = 0;
231                                            break;
232    
233                                            default:
234                                            numbers[number_count] = keyboard_entered;
235                                            
236                                            //numbers; // got to catch 0-9; 20 byte array.
237                                            number_count++; // amount of used bytes in numbers.
238                                    }
239                                    
240                            }
241    /*
242                            network_send_hello( 0x01 );
243    
244  #if defined(MCHP_C18)                          strncpy(global_network_char, "12345678", 8);
245  #pragma code highVector=0x08                          network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
246  void HighVector (void)                          
247  {                          strncpy(global_network_char, "87654444", 8);
248      _asm goto HighISR _endasm                          network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8
249    
250                            network_send_calc_total();
251                            
252                            network_send_cash_payed(50000);
253                            
254                            network_send_cancel_last();
255                            
256                            network_send_cancel_all();
257                                                    
258                            network_send_goodbye();
259     */
260        }
261  }  }
 #pragma code /* return to default code section */  
 #endif  
262    
263  static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD)  void interrupt HighISR(void)
264  {  {
265      char IPDigit[8];          if (RCIF == 1)
266                    barcode_interrupt();
267      if ( bToLCD )          else
268      {          TickUpdate();
269          /*  }
          * 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('.');  
     }  
270    
     itoa(IPVal->v[2], IPDigit);  
     if ( bToLCD )  
     {  
         XLCDPutString(IPDigit);  
         XLCDPut('.');  
     }  
271    
     itoa(IPVal->v[3], IPDigit);  
     if ( bToLCD )  
         XLCDPutString(IPDigit);  
 }  
272    
273  /*********************************************************************  /*********************************************************************
274   * Function:        void InitializeBoard(void)   * Function:        void InitializeBoard(void)
# Line 395  static void InitializeBoard(void) Line 297  static void InitializeBoard(void)
297      /*      /*
298       * LCD is enabled using RA5.       * LCD is enabled using RA5.
299       */       */
300      PORTA_RA5 = 0;          // Disable LCD.  //    PORTA_RA5 = 0;          // Disable LCD.
301    
302      /*      /*
303       * Turn off the LED's.       * Turn off the LED's.
# Line 409  static void InitializeBoard(void) Line 311  static void InitializeBoard(void)
311       */       */
312      INTCON2_RBPU = 0;      INTCON2_RBPU = 0;
313    
     XLCDInit();  
     XLCDGoto(0, 0);  
     XLCDPutROMString(StartupMsg);  
   
314      T0CON = 0;      T0CON = 0;
315      INTCON_GIEH = 1;      INTCON_GIEH = 1;
316      INTCON_GIEL = 1;      INTCON_GIEL = 1;
# Line 496  BOOL StringToIPAddress(char *str, IP_ADD Line 394  BOOL StringToIPAddress(char *str, IP_ADD
394      return (byteIndex == 3);      return (byteIndex == 3);
395  }  }
396    
   
397  void XLCDDelay15ms(void)  void XLCDDelay15ms(void)
398  {  {
399      DelayMs(15);      DelayMs(15);

Legend:
Removed from v.91  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.20