#include <stdio.h> #include <stdint.h> #pragma pack(push, 2) typedef union { uint16_t all; struct { uint16_t time_set1 : 2; uint16_t time_set2 : 2; uint16_t time_set3 : 2; uint16_t time_set4 : 2; uint16_t time_set5 : 2; uint16_t time_set6 : 2; uint16_t time_set7 : 2; uint16_t time_set8 : 2; }; }time1_t; typedef union { uint16_t all; struct { uint16_t time_set9 : 2; uint16_t time_set10 : 2; }; }time2_t; typedef struct { union { uint16_t all; struct { uint16_t bitmap : 7; uint16_t onoff : 2; }; } week_set; union { uint16_t all; struct { uint16_t min : 8; uint16_t hour : 8; }; } time; } time_args_t; #pragma pack() time_args_t time_args[10]; time1_t time1; time2_t time2; int main() { time1.time_set1 = 1; time1.time_set2 = 1; time1.time_set3 = 1; time1.time_set4 = 1; time1.time_set5 = 1; time1.time_set6 = 1; time1.time_set7 = 1; time1.time_set8 = 1; time2.time_set9 = 1; time2.time_set10 = 1; printf("time1: 14704-%02x, time2: 14705-%02x\n", time1.all, time2.all); printf("x32-%02x%02x\n", time2.all, time1.all); time_args[0].week_set.bitmap = 0b0000001; time_args[0].week_set.onoff = 1; time_args[0].time.hour = 1; time_args[0].time.min = 30; time_args[1].week_set.bitmap = 0b0000010; time_args[1].week_set.onoff = 0; time_args[1].time.hour = 4; time_args[1].time.min = 40; time_args[2].week_set.bitmap = 0b0000100; time_args[2].week_set.onoff = 1; time_args[2].time.hour = 7; time_args[2].time.min = 5; time_args[3].week_set.bitmap = 0b0001000; time_args[3].week_set.onoff = 0; time_args[3].time.hour = 10; time_args[3].time.min = 45; time_args[4].week_set.bitmap = 0b0010000; time_args[4].week_set.onoff = 1; time_args[4].time.hour = 13; time_args[4].time.min = 12; time_args[5].week_set.bitmap = 0b0100000; time_args[5].week_set.onoff = 0; time_args[5].time.hour = 16; time_args[5].time.min = 15; time_args[6].week_set.bitmap = 0b1000000; time_args[6].week_set.onoff = 1; time_args[6].time.hour = 19; time_args[6].time.min = 32; time_args[7].week_set.bitmap = 0b0000100; time_args[7].week_set.onoff = 0; time_args[7].time.hour = 22; time_args[7].time.min = 54; time_args[8].week_set.bitmap = 0b0010000; time_args[8].week_set.onoff = 1; time_args[8].time.hour = 23; time_args[8].time.min = 22; time_args[9].week_set.bitmap = 0b1000000; time_args[9].week_set.onoff = 0; time_args[9].time.hour = 0; time_args[9].time.min = 0; int base = 14712; for (int i = 0; i < 10; i++) { printf("time arg[%d]: week: %d-%04x, time: %d-%04x\n", i, base, time_args[i].week_set.all, base+1, time_args[i].time.all); base += 2; } for (int i = 0; i < 10; i++) { printf("x32-%04x%04x,", time_args[i].time.all, time_args[i].week_set.all); if (i == 4) printf("\n"); } return 0; }
标签:week,123,set,args,time1,uint16,time From: https://www.cnblogs.com/yeshenmeng/p/18140737