首页 智能电表主控程序源代码

智能电表主控程序源代码

举报
开通vip

智能电表主控程序源代码/*********************************************************************************************** ********* 2 程序名称:智能电表主控程序 3 程序设计:freevanx、LDZ 4 时间:2006-9-29 5 功能: 1、计算电量、电费 6 2、接受键盘输入,将所要求的信息显示在LCD上 7 3、通过键盘设置内部计费参照,适应不同种类的器材,不同的 8 地区,不同的电价,不同的计费时段。 ...

智能电表主控程序源代码
/*********************************************************************************************** ********* 2 程序名称:智能电表主控程序 3 程序设计:freevanx、LDZ 4 时间:2006-9-29 5 功能: 1、计算电量、电费 6 2、接受键盘输入,将所要求的信息显示在LCD上 7 3、通过键盘设置内部计费参照,适应不同种类的器材,不同的 8 地区,不同的电价,不同的计费时段。 9 10 备注:◎版权所有,此程序仅可参考,未经授权,不得复制,分发。 11 12 编译方法:将main.c 13 characterlib.h 14 C51FPS.LIB 15 STARTUP.A51(不是必需文件) 16 添加到同一Group,然后 17 18 1、在工程文件列表中的main.c文件上右击鼠标 19 2、选择Options for file “main.c”,打开一个对话框, 20 3、在Properties选项卡的右边激活 Generate Assembler SRC file 复选框 21 4、在同一位置激活 Assemble SRC file. 复选框 22 23 ************************************************************************************************ ********/ 24 25 /************************************************** 26 REG51.h 包含各种寄存器的定义 27 math.h 使用了其中的ceil()和pow()函数 28 string.h 使用了其中的memset()函数 29 characterlib.h 自定义头文件,包含所有的字库 30 定义了uchar,因为头文件中要用到 31 ****************************************************/ 32 #include 33 #include 34 #include 35 //#include "characterlib.h" 36 37 /************************************************** 38 8255的各种命令字,通过控制8255的PC口控制LCD芯片的各种显示 39 方式 40 ****************************************************/ 41 #define TYPE_COMMAND 0x0e 42 #define TYPE_DATA 0x0f 43 #define RESET 0x09 44 45 /************************************************** 46 LCD芯片的命令字 47 ****************************************************/ 48 #define CS1_LOW 0x0c 49 #define CS1_HIGH 0x0d 50 #define CS2_LOW 0x06 51 #define CS2_HIGH 0x07 52 53 #define SOFT_RESET 0xe2 54 55 #define DISPLAY_ON 0xaf 56 #define PAGE_BASIC 0xb8 57 #define COLUMN0 0x00 58 59 60 typedef unsigned char uchar; 61 62 /************************************************** 63 各种初值定义,作为计算的基本单位 64 ****************************************************/ 65 struct initset 66 { 67 float high_fee; 68 float low_fee; 69 unsigned char highrange_start; 70 unsigned char highrange_end; 71 unsigned char lowrange_start; 72 unsigned char lowrange_end; 73 int rotate_Speed; 74 }; 75 /************************************************** 76 电量计定义,记录电量使用情况 77 ****************************************************/ 78 struct coulometer 79 { 80 int high; 81 int low; 82 int total; 83 }; 84 /************************************************** 85 电费计定义,记录用电电费 86 ****************************************************/ 87 struct fee 88 { 89 float high; 90 float low; 91 float total; 92 }; 93 94 /************************************************** 95 各个外部存储器或者端口地址的绝对定位定义 96 ****************************************************/ 97 volatile unsigned char xdata RAM6264 _at_ 0x1FF0; 98 99 volatile unsigned char xdata CommandPortOf8279 _at_ 0x5FFF; 100 volatile unsigned char xdata DataOf8279 _at_ 0x5EFF; 101 102 volatile unsigned char xdata CommandPortOf8255 _at_ 0xBFFF; 103 volatile unsigned char xdata APortOf8255 _at_ 0xBFFC; 104 volatile unsigned char xdata CPortOf8255 _at_ 0xBFFE; 105 106 /************************************************** 107 设置LCD芯片各页的命令字 108 ****************************************************/ 109 uchar idata page[4]={0xb8,0xb9,0xba,0xbb}; 110 111 /***************************************************** 112 键盘程序中使用到全局变量 113 *******************************************************/ 114 uchar idata WhichFunctionKey=0x00; 115 116 /***************************************************** 117 整个程序中共享的全局变量,智能电表的基本数据 118 *******************************************************/ 119 struct initset idata Set={0.8 ,0.6, 6, 21, 22, 5 ,1000}; 120 struct coulometer idata Coulo={0,0,0}; 121 struct fee idata Fee={0.0,0.0,0.0}; 122 123 /***************************************************** 124 各个提示信息的下半行,显示实际的数据,由于要改动,所以 125 不能放在code段 126 *******************************************************/ 127 uchar xdata HighCoulometerTextBottom[8][32]=0; 128 uchar xdata LowCoulometerTextBottom[8][32]=0; 129 uchar xdata AllCoulometerTextBottom[8][32]=0; 130 uchar xdata HighFeeTextBottom[8][32]=0; 131 uchar xdata LowFeeTextBottom[8][32]=0; 132 uchar xdata AllFeeTextBottom[8][32]=0; 133 uchar xdata HighFeeSetTextBottom[8][32]=0; 134 uchar xdata LowFeeSetTextBottom[8][32]=0; 135 uchar xdata RotateSpeedSetTextBottom[8][32]=0; 136 uchar xdata HighStartSetTextBottom[8][32]=0; 137 uchar xdata HighEndSetTextBottom[8][32]=0; 138 139 /***************************************************** 140 字库,如果放在头文件中,低版本的Keil编译时会报错,所以拿过来了141 *******************************************************/ 142 uchar code HighCoulometerTextTop[8][32]=/*高峰用电量 */ 143 { 144 { //高 145 0x04,0x04,0x04,0x0F4,0x94,0x94,0x95,0x96, 146 0x94,0x94,0x94,0x0F4,0x04,0x06,0x04,0x00, 147 0x00,0x0FE,0x02,0x02,0x7A,0x4A,0x4A,0x4A, 148 0x4A,0x4A,0x7A,0x02,0x82,0x0FF,0x02,0x00 149 }, 150 { //峰 151 0x00,0x0F0,0x00,0x0FF,0x00,0x0F0,0x90,0x88, 152 0x4F,0x54,0x0A4,0x54,0x4C,0x0C4,0x40,0x00, 153 0x00,0x1F,0x10,0x0F,0x08,0x1F,0x00,0x14, 154 0x15,0x15,0x0FF,0x15,0x15,0x14,0x00,0x00 155 }, 156 { //用 157 0x00,0x00,0x0FE,0x22,0x22,0x22,0x22,0x0FE, 158 0x22,0x22,0x22,0x22,0x0FF,0x02,0x00,0x00, 159 0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F, 160 0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00 161 }, 162 { //电 164 0x48,0x48,0x48,0x0FC,0x08,0x00,0x00,0x00, 165 0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42, 166 0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00 167 }, 168 { //量 169 0x20,0x20,0x20,0x0BE,0x0AA,0x0AA,0x0AA,0x0AA, 170 0x0AA,0x0AA,0x0AA,0x0BF,0x22,0x30,0x20,0x00, 171 0x00,0x80,0x80,0x0AF,0x0AA,0x0AA,0x0AA,0x0FF, 172 0x0AA,0x0AA,0x0AA,0x0AF,0x80,0x80,0x00,0x00 173 } 174 175 }; 176 177 uchar code LowCoulometerTextTop[8][32]=/*;低谷用电量 */ 178 { 179 { //低 180 0x40,0x20,0x0F8,0x07,0x00,0x0FC,0x84,0x84, 181 0x84,0x0FC,0x82,0x82,0x83,0x0C2,0x80,0x00, 182 0x00,0x00,0x0FF,0x00,0x00,0x7F,0x20,0x10, 183 0x08,0x20,0x47,0x18,0x60,0x80,0x70,0x00 184 185 }, 186 { //谷 187 0x00,0x10,0x08,0x04,0x83,0x40,0x20,0x18, 188 0x20,0x41,0x82,0x86,0x0C,0x00,0x00,0x00, 189 0x02,0x02,0x01,0x0FD,0x44,0x44,0x44,0x44, 190 0x44,0x44,0x44,0x0FC,0x01,0x03,0x01,0x00 191 }, 192 { //用 193 0x00,0x00,0x0FE,0x22,0x22,0x22,0x22,0x0FE, 194 0x22,0x22,0x22,0x22,0x0FF,0x02,0x00,0x00, 195 0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F, 196 0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00 197 }, 198 { //电 199 0x00,0x0F8,0x48,0x48,0x48,0x48,0x0FF,0x48, 200 0x48,0x48,0x48,0x0FC,0x08,0x00,0x00,0x00, 201 0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42, 202 0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00 203 }, 204 { //量 205 0x20,0x20,0x20,0x0BE,0x0AA,0x0AA,0x0AA,0x0AA, 206 0x0AA,0x0AA,0x0AA,0x0BF,0x22,0x30,0x20,0x00, 207 0x00,0x80,0x80,0x0AF,0x0AA,0x0AA,0x0AA,0x0FF, 208 0x0AA,0x0AA,0x0AA,0x0AF,0x80,0x80,0x00,0x00 209 } 210 }; 211 212 uchar code AllCoulometerTextTop[8][32]=/*;总用电量 */ 213 { 214 { //总 215 0x00,0x00,0x00,0x0F1,0x12,0x14,0x10,0x10, 216 0x10,0x14,0x12,0x0F9,0x10,0x00,0x00,0x00, 217 0x20,0x18,0x00,0x30B,0x41,0x41,0x45,0x49, 219 }, 220 { //用 221 0x00,0x00,0x0FE,0x22,0x22,0x22,0x22,0x0FE, 222 0x22,0x22,0x22,0x22,0x0FF,0x02,0x00,0x00, 223 0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F, 224 0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00 225 }, 226 { //电 227 0x00,0x0F8,0x48,0x48,0x48,0x48,0x0FF,0x48, 228 0x48,0x48,0x48,0x0FC,0x08,0x00,0x00,0x00, 229 0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42, 230 0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00 231 232 }, 233 { //量 234 0x20,0x20,0x20,0x0BE,0x0AA,0x0AA,0x0AA,0x0AA, 235 0x0AA,0x0AA,0x0AA,0x0BF,0x22,0x30,0x20,0x00, 236 0x00,0x80,0x80,0x0AF,0x0AA,0x0AA,0x0AA,0x0FF, 237 0x0AA,0x0AA,0x0AA,0x0AF,0x80,0x80,0x00,0x00 238 } 239 }; 240 241 uchar code HighFeeTextTop[8][32]=/*;高峰时段电费*/ 242 { 243 { //高 244 0x04,0x04,0x04,0x0F4,0x94,0x94,0x95,0x96, 245 0x94,0x94,0x94,0x0F4,0x04,0x06,0x04,0x00, 246 0x00,0x0FE,0x02,0x02,0x7A,0x4A,0x4A,0x4A, 247 0x4A,0x4A,0x7A,0x02,0x82,0x0FF,0x02,0x00 248 }, 249 { //峰 250 0x00,0x0F0,0x00,0x0FF,0x00,0x0F0,0x90,0x88, 251 0x4F,0x54,0x0A4,0x54,0x4C,0x0C4,0x40,0x00, 252 0x00,0x1F,0x10,0x0F,0x08,0x1F,0x00,0x14, 253 0x15,0x15,0x0FF,0x15,0x15,0x14,0x00,0x00 254 255 }, 256 { //时 257 0x00,0x0FC,0x84,0x84,0x84,0x0FE,0x14,0x10, 258 0x90,0x10,0x10,0x10,0x0FF,0x10,0x10,0x00, 259 0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00, 260 0x00,0x23,0x40,0x80,0x7F,0x00,0x00,0x00 261 }, 262 { //段 263 0x00,0x00,0x0FC,0x24,0x24,0x0B2,0x22,0x40, 264 0x3E,0x02,0x02,0x02,0x3F,0x42,0x40,0x00, 265 0x10,0x10,0x0FF,0x09,0x09,0x09,0x89,0x80, 266 0x47,0x29,0x11,0x2D,0x43,0x0C0,0x40,0x00 267 268 }, 269 { //电 270 0x00,0x0F8,0x48,0x48,0x48,0x48,0x0FF,0x48, 271 0x48,0x48,0x48,0x0FC,0x08,0x00,0x00,0x00, 272 0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,
本文档为【智能电表主控程序源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_882336
暂无简介~
格式:doc
大小:39KB
软件:Word
页数:0
分类:互联网
上传时间:2019-07-27
浏览量:83