Subversion Repositories HomeAutomation

Rev

Rev 1018 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
679 noddan 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
 
763 noddan 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));
679 noddan 98
 
99
 
763 noddan 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);
679 noddan 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
 
1790 arune 159
    //Initiera utg\8Cngar
763 noddan 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);
1790 arune 163
    glcdInit();
679 noddan 164
 
165
    glcdSetXY(0,0);
763 noddan 166
    glcdSetXY(0,0);
167
    glcdSetXY(0,0);
679 noddan 168
 
1018 linlun 169
    //glcdPutStr("This is a test....... Let us try another row.. And another.. And some more..",1);
679 noddan 170
 
171
    for (jxa = 0; jxa< 8; jxa++){
172
        glcdSetXY(0,jxa);
173
        for (ixa = 0; ixa < 128; ixa++){
1018 linlun 174
            glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128),1);
679 noddan 175
        }
176
    }
177
 
763 noddan 178
 
179
 
180
    //glcdSetXY(0,0);
181
    //glcdPutStr("I can write text. This is cool. Yeah baby! Pixelina!");
182
 
679 noddan 183
    /*glcdSetXY(5,5);
1018 linlun 184
    glcdPutStr("I can write text.",1);
679 noddan 185
    glcdSetXY(8,10);
1018 linlun 186
    glcdPutStr("Everywhere!",1);
679 noddan 187
    */
188
 
763 noddan 189
 
190
 
679 noddan 191
    while (1) {
192
 
193
 
194
        if (rxMsgFull) {
763 noddan 195
            uint16_t sns_type;
196
            uint8_t snsid;
1790 arune 197
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_SNS){// FIXME ett j\8Akla herk, st\8Ada upp
763 noddan 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];
812 noddan 206
                    for (jxa = 0; jxa< 8; jxa++){
207
                        glcdSetXY(0,jxa);
208
                        for (ixa = 0; ixa < 128; ixa++){
1018 linlun 209
 
210
glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128),1);
812 noddan 211
                        }
212
                    }
763 noddan 213
 
214
 
215
 
216
                    char buffer[20];   
217
 
218
                    unsignedtoascii(sensor_Temperature,SNS_DECPOINT_TEMPERATURE,buffer,1);
219
 
220
                    if (rxMsg.Id == 0x040a0413){
221
                        glcdSetXY(78,1);
1018 linlun 222
                        glcdPutStr("UT:",1);
223
                        glcdPutStr(buffer,1);
224
                        //glcdPutStr("C",1);
763 noddan 225
                    } else if (rxMsg.Id == 0x040a0213) {
226
                        glcdSetXY(78,2);
1018 linlun 227
                        glcdPutStr("IN:",1);
228
                        glcdPutStr(buffer,1);
229
                        //glcdPutStr("C",1);
763 noddan 230
                    } else if (rxMsg.Id == 0x040a0211) {
231
                        glcdSetXY(78,3);
1018 linlun 232
                        glcdPutStr("TV:",1);
233
                        glcdPutStr(buffer,1);
234
                        //glcdPutStr("C",1);
763 noddan 235
                    }
236
 
237
                break;
238
                }
239
            }
240
            rxMsgFull = 0;
679 noddan 241
        }
242
    }
243
 
244
    return 0;
245
}
763 noddan 246
 
1790 arune 247
    //\87 la pengi. Skall libbifieras.
763 noddan 248
    void numtoascii( int16_t num, char **str ) {
249
        if( num==0 ) return;
250
        numtoascii( num/10, str );
251
        **str = '0' + (num%10);
252
        (*str)++;
253
    }
254
 
255
    void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
256
        uint8_t i;
257
 
258
        if( num<0 ) {
259
            *(string++) = '-';
260
            num = -num;
261
        }
262
        numtoascii(num>>decimalplace, &string );
263
        if(numberofdecimals!=0) *(string++) = '.';
264
        for(i=0;i<numberofdecimals;i++) {
265
            num %= 1<<decimalplace;
266
            num *= 10;
267
            *(string++) = '0' + (num>>decimalplace);
268
        }
269
        *(string++) = 0;
270
    }
271
 
272
    void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
273
        uint8_t i;
274
        numtoascii(num>>decimalplace, &string );
275
        if(numberofdecimals!=0) *(string++) = '.';
276
        for(i=0;i<numberofdecimals;i++) {
277
            num %= 1<<decimalplace;
278
            num *= 10;
279
            *(string++) = '0' + (num>>decimalplace);
280
        }
281
        *(string++) = 0;
282
    }