Subversion Repositories HomeAutomation

Rev

Rev 763 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #include <inttypes.h>
  2. #include <avr/interrupt.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <config.h> // All configuration parameters
  6. #include <bios.h>   // BIOS interface declarations, including CAN structure and ID defines.
  7. #include <drivers/timer/timer.h>
  8.  
  9. #include <drivers/lcd/glcd/ks0108.h>
  10. #include <drivers/lcd/glcd/font.h>
  11.  
  12. #include <avr/pgmspace.h>
  13.  
  14. #define APP_TYPE    0xf001
  15. #define APP_VERSION 0x0002
  16.  
  17. /*
  18. static unsigned char Splash_left[] PROGMEM = {
  19.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  20.           15,231,  3,241,250,171,115,181, 53, 54,110,254,254,254,110,180,
  21.           53, 53,113,171,251,242,240,  3, 15,255,255,255,255,255,255,255,
  22.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  23.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  24.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  25.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  26.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  27.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  28.            0,255,252,227, 31,191,127,254,254,255,191,119,119,119,191,255,
  29.          254,254,255,127, 63,223,227,252,252,129, 63,255,255,255,255,255,
  30.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  31.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  32.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  33.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  34.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  35.          255,255,255,255,255,255,255,255,255,255,255,255,127, 31,135,217,
  36.          220,223,  7,  1, 12, 47, 47,118,118,121,125,251,251,251,251,125,
  37.          121,118, 54, 15, 12,  9,  7, 15,223,223,216,167,143, 63,255,255,
  38.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  39.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  40.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  41.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  42.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  43.          255,255,255,255,255,255,255,255,255,255, 15,240,254,255,255,255,
  44.            7,  3,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  45.            0,  0,  0,  0,  0,  0,  0,  0,  3,  7,255,255,255,255,240, 15,
  46.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  47.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  48.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  49.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  50.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  51.          255,255,255,255,255,255,255,255,127,131,252,255,255,255,255,159,
  52.          224,248,240,240,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  53.            0,  0,  0,  0,  0,  0,240,240,248,224, 31,255,255,255,255,252,
  54.          131,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  55.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  56.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  57.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  58.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  59.          255,255,255,255,255,255,255,255,  0,255,255,255, 31,225,254,255,
  60.          255,127, 31,  7,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  61.            0,  0,  0,  0,  0,  0,  7, 31,127,255,255,254,225, 31,255,255,
  62.          255,  0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  63.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  64.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  65.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  66.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  67.          255,255,255,255,255,255,255,  7,248,255,255, 15,240,255,255, 15,
  68.           19, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  69.           28, 28, 28, 28, 28, 28, 28, 28, 28, 19, 15,255,255,240, 15,255,
  70.          255,248,  7,255,255,255,255,255,255,255,255,255,255,255,255,255,
  71.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  72.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  73.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  74.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  75.          255,191, 95, 95,111,119,121,126,159,127,135,248,255,255,255,128,
  76.            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,248,248,  0,  0,
  77.            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,128,255,255,255,248,135,
  78.          127,159,126,121,119,111, 95, 95,191,255,255,255,255,255,255,255,
  79.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  80.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  81.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
  82.          255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
  83. };
  84. */
  85. static unsigned char Splash_left[] PROGMEM = {
  86. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xe7,0x3,0xf1,0xfa,0xab,0x73,0xb5,0x35,0x36,0x6e,0xfe,0xfe,0xfe,0x6e,0xb4,0x35,0x35,0x71,0xab,0xfb,0xf2,0xf0,0x3,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0x7,0xff,//Line 1
  87. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xfc,0xe3,0x1f,0xbf,0x7f,0xfe,0xfe,0xff,0xbf,0x77,0x77,0x77,0xbf,0xff,0xfe,0xfe,0xff,0x7f,0x3f,0xdf,0xe3,0xfc,0xfc,0x81,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 2
  88. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x1f,0x87,0xd9,0xdc,0xdf,0x7,0x1,0xc,0x2f,0x2f,0x76,0x76,0x79,0x7d,0xfb,0xfb,0xfb,0xfb,0x7d,0x79,0x76,0x36,0xf,0xc,0x9,0x7,0xf,0xdf,0xdf,0xd8,0xa7,0x8f,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 3
  89. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xf0,0xfe,0xff,0xff,0xff,0x7,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x7,0xff,0xff,0xff,0xff,0xf0,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 4
  90. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x83,0xfc,0xff,0xff,0xff,0xff,0x9f,0xe0,0xf8,0xf0,0xf0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf0,0xf0,0xf8,0xe0,0x1f,0xff,0xff,0xff,0xff,0xfc,0x83,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 5
  91. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0x1f,0xe1,0xfe,0xff,0xff,0x7f,0x1f,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1f,0x7f,0xff,0xff,0xfe,0xe1,0x1f,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0x3,0xb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xb,0x3,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfc,0xff,//Line 6
  92. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7,0xf8,0xff,0xff,0xf,0xf0,0xff,0xff,0xf,0x13,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x13,0xf,0xff,0xff,0xf0,0xf,0xff,0xff,0xf8,0x7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//Line 7
  93. 0xff,0xbf,0x5f,0x5f,0x6f,0x77,0x79,0x7e,0x9f,0x7f,0x87,0xf8,0xff,0xff,0xff,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf8,0xf8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0xff,0xff,0xff,0xf8,0x87,0x7f,0x9f,0x7e,0x79,0x77,0x6f,0x5f,0x5f,0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x0,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff//Line 7
  94. };
  95. uint16_t ixa = 0;
  96. uint8_t jxa = 0;
  97. uint16_t sensor_Temperature = 12.7*(2<<(SNS_DECPOINT_VOLTAGE-1));
  98.  
  99.  
  100. void numtoascii( int16_t num, char **str );
  101. void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  102. void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  103.  
  104.  
  105.  
  106.  
  107. // A simple message "queue", with space for one message only.
  108. // These are declared volatile to tell the compiler not to optimize away accesses.
  109. volatile Can_Message_t rxMsg; // Message storage
  110. volatile uint8_t rxMsgFull;   // Synchronization flag
  111.  
  112. // CAN message reception callback.
  113. // This function runs with interrupts disabled, keep it as short as possible.
  114. void can_receive(Can_Message_t *msg) {
  115.     if (!rxMsgFull) {
  116.         memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
  117.         rxMsgFull = 1;
  118.     }
  119. }
  120.  
  121. // Timer callback function used for some timer tests
  122. void timer_callback(uint8_t timer) {
  123.     Can_Message_t msg;
  124.    
  125.     msg.ExtendedFlag = 1;
  126.     msg.Id = (CAN_TST << CAN_SHIFT_CLASS) | NODE_ID;
  127.     msg.RemoteFlag = 0;
  128.     msg.DataLength = 1;
  129.     msg.Data.bytes[0] = timer;
  130.    
  131.     BIOS_CanSend(&msg);
  132. }
  133.  
  134. int main(void)
  135. {
  136.    
  137.    
  138.     // Enable interrupts as early as possible
  139.     sei();
  140.    
  141.     unsigned long time;
  142.    
  143.     Can_Message_t txMsg;
  144.     txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
  145.     txMsg.DataLength = 4;
  146.     txMsg.RemoteFlag = 0;
  147.     txMsg.ExtendedFlag = 1;
  148.     txMsg.Data.words[0] = APP_TYPE;
  149.     txMsg.Data.words[1] = APP_VERSION;
  150.    
  151.     // Set up callback for CAN reception, this is optional if only sending is required.
  152.     BIOS_CanCallback = &can_receive;
  153.     // Send CAN_NMT_APP_START
  154.     BIOS_CanSend(&txMsg);
  155.    
  156.    
  157.    
  158.    
  159.     //Initiera utgŒngar
  160.     DDRB |= (1<<7)|(1<<2)|(1<<1)|(1<<0);
  161.     DDRC |= (1<<5)|(1<<4);  
  162.     DDRD |= (1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<2)|(1<<1)|(1<<0);
  163.     glcdPowerOn();
  164.  
  165.     glcdSetXY(0,0);
  166.     glcdSetXY(0,0);
  167.     glcdSetXY(0,0);
  168.  
  169.     //glcdPutStr("This is a test....... Let us try another row.. And another.. And some more..");
  170.  
  171.     for (jxa = 0; jxa< 8; jxa++){
  172.         glcdSetXY(0,jxa);
  173.         for (ixa = 0; ixa < 128; ixa++){
  174.             glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
  175.         }
  176.     }
  177.    
  178.    
  179.  
  180.     //glcdSetXY(0,0);
  181.     //glcdPutStr("I can write text. This is cool. Yeah baby! Pixelina!");
  182.    
  183.     /*glcdSetXY(5,5);
  184.     glcdPutStr("I can write text.");
  185.     glcdSetXY(8,10);
  186.     glcdPutStr("Everywhere!");
  187.     */
  188.    
  189.  
  190.    
  191.     while (1) {
  192.  
  193.        
  194.         if (rxMsgFull) {
  195.             uint16_t sns_type;
  196.             uint8_t snsid;
  197.             if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_SNS){// FIXME ett jŠkla herk, stŠda upp
  198.            
  199.                 sns_type = (uint16_t)((rxMsg.Id & CAN_MASK_SNS_TYPE) >> CAN_SHIFT_SNS_TYPE);
  200.                 snsid = (uint8_t)((rxMsg.Id & CAN_MASK_SNS_ID) >> CAN_SHIFT_SNS_ID);
  201.                
  202.                 switch(sns_type)
  203.                 {
  204.                 case SNS_TYPE_TEMPERATURE:
  205.                     sensor_Temperature = rxMsg.Data.words[0];
  206.                    
  207.  
  208.  
  209.                     char buffer[20];   
  210.  
  211.                     unsignedtoascii(sensor_Temperature,SNS_DECPOINT_TEMPERATURE,buffer,1);
  212.                    
  213.                     if (rxMsg.Id == 0x040a0413){
  214.                         glcdSetXY(78,1);
  215.                         glcdPutStr("UT:");
  216.                         glcdPutStr(buffer);
  217.                         //glcdPutStr("C");
  218.                     } else if (rxMsg.Id == 0x040a0213) {
  219.                         glcdSetXY(78,2);
  220.                         glcdPutStr("IN:");
  221.                         glcdPutStr(buffer);
  222.                         //glcdPutStr("C");
  223.                     } else if (rxMsg.Id == 0x040a0211) {
  224.                         glcdSetXY(78,3);
  225.                         glcdPutStr("TV:");
  226.                         glcdPutStr(buffer);
  227.                         //glcdPutStr("C");
  228.                     }
  229.  
  230.                 break;
  231.                 }
  232.             }
  233.             rxMsgFull = 0;
  234.         }
  235.     }
  236.    
  237.     return 0;
  238. }
  239.  
  240.     //‡ la pengi. Skall libbifieras.
  241.     void numtoascii( int16_t num, char **str ) {
  242.         if( num==0 ) return;
  243.         numtoascii( num/10, str );
  244.         **str = '0' + (num%10);
  245.         (*str)++;
  246.     }
  247.  
  248.     void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  249.         uint8_t i;
  250.  
  251.         if( num<0 ) {
  252.             *(string++) = '-';
  253.             num = -num;
  254.         }
  255.         numtoascii(num>>decimalplace, &string );
  256.         if(numberofdecimals!=0) *(string++) = '.';
  257.         for(i=0;i<numberofdecimals;i++) {
  258.             num %= 1<<decimalplace;
  259.             num *= 10;
  260.             *(string++) = '0' + (num>>decimalplace);
  261.         }
  262.         *(string++) = 0;
  263.     }
  264.  
  265.     void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  266.         uint8_t i;
  267.         numtoascii(num>>decimalplace, &string );
  268.         if(numberofdecimals!=0) *(string++) = '.';
  269.         for(i=0;i<numberofdecimals;i++) {
  270.             num %= 1<<decimalplace;
  271.             num *= 10;
  272.             *(string++) = '0' + (num>>decimalplace);
  273.         }
  274.         *(string++) = 0;
  275.     }
  276.