分享一个计算机控制的实验例程
2014-05-12 22:41
351 查看
程序是老师写好的,但是我觉得很有参考价值,毕竟之前没用C写过采集及AD转换之类的程序
程序如下:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit DAT=P2^5;
sbit CLK=P2^4;
sbit CS=P2^3;
uint LTC1292(void)
{
uint i,x;
CLK=0; DAT=1; CS=0;
for(i=0;i<14;i++)
{
CLK=1; x<<=1;
if(DAT==1) x++;
CLK=0;
}
CS=1;
return (x&0xfff);
}
void delay(uint t)
{
while(t--);
}
#define LCD_COM 0 // Command
#define LCD_DAT 1 // Data
sbit LcdRS=P2^0;
sbit LcdRW=P2^1;
sbit LcdEN=P2^2;
void time(unsigned int t)
{
unsigned int i;
for(i=0;i<t;i++);
}
void LCD_WRITE(unsigned char x,bit WS)
{
P0=x;
LcdRW=0; LcdRS=WS;
LcdEN=1; time(50); LcdEN=0;
}
void LCD_Initial()
{
LCD_WRITE(0x38,LCD_COM); time(120);
LCD_WRITE(0x38,LCD_COM); time(120);
LCD_WRITE(0x01,LCD_COM); time(120);
LCD_WRITE(0x06,LCD_COM); time(120);
LCD_WRITE(0x0c,LCD_COM); time(120);
}
void GotoXY(unsigned char x,unsigned char y)
{
unsigned char code table[4]={0x00,0x40,0x10,0x50};
LCD_WRITE(0x80+table[x]+y, LCD_COM);
}
void PutCh(char m)
{
LCD_WRITE(m,LCD_DAT);
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
PutCh(*str);
str++;
}
}
void main()
{
uint m;
ulong y;
LCD_Initial();
GotoXY(0,0); Print("LTC1292 Test....");
GotoXY(1,0); Print("AD= ");
GotoXY(1,8); Print("V= v");
while(1)
{
delay(2000);
y=LTC1292();
GotoXY(1,3);
PutCh(y/1000+'0');
PutCh((y/100)%10+'0');
PutCh((y/10)%10+'0');
PutCh(y%10+'0');
y=y*125;
m=y/4095;
GotoXY(1,10);
PutCh((m/100)%10+'0');
// PutCh('.');
PutCh((m/10)%10+'0');
PutCh(m%10+'0');
}
}
改变TCK的温度就可以采集相应的电压
程序如下:
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit DAT=P2^5;
sbit CLK=P2^4;
sbit CS=P2^3;
uint LTC1292(void)
{
uint i,x;
CLK=0; DAT=1; CS=0;
for(i=0;i<14;i++)
{
CLK=1; x<<=1;
if(DAT==1) x++;
CLK=0;
}
CS=1;
return (x&0xfff);
}
void delay(uint t)
{
while(t--);
}
#define LCD_COM 0 // Command
#define LCD_DAT 1 // Data
sbit LcdRS=P2^0;
sbit LcdRW=P2^1;
sbit LcdEN=P2^2;
void time(unsigned int t)
{
unsigned int i;
for(i=0;i<t;i++);
}
void LCD_WRITE(unsigned char x,bit WS)
{
P0=x;
LcdRW=0; LcdRS=WS;
LcdEN=1; time(50); LcdEN=0;
}
void LCD_Initial()
{
LCD_WRITE(0x38,LCD_COM); time(120);
LCD_WRITE(0x38,LCD_COM); time(120);
LCD_WRITE(0x01,LCD_COM); time(120);
LCD_WRITE(0x06,LCD_COM); time(120);
LCD_WRITE(0x0c,LCD_COM); time(120);
}
void GotoXY(unsigned char x,unsigned char y)
{
unsigned char code table[4]={0x00,0x40,0x10,0x50};
LCD_WRITE(0x80+table[x]+y, LCD_COM);
}
void PutCh(char m)
{
LCD_WRITE(m,LCD_DAT);
}
void Print(unsigned char *str)
{
while(*str!='\0')
{
PutCh(*str);
str++;
}
}
void main()
{
uint m;
ulong y;
LCD_Initial();
GotoXY(0,0); Print("LTC1292 Test....");
GotoXY(1,0); Print("AD= ");
GotoXY(1,8); Print("V= v");
while(1)
{
delay(2000);
y=LTC1292();
GotoXY(1,3);
PutCh(y/1000+'0');
PutCh((y/100)%10+'0');
PutCh((y/10)%10+'0');
PutCh(y%10+'0');
y=y*125;
m=y/4095;
GotoXY(1,10);
PutCh((m/100)%10+'0');
// PutCh('.');
PutCh((m/10)%10+'0');
PutCh(m%10+'0');
}
}
改变TCK的温度就可以采集相应的电压
相关文章推荐
- 一个对计算机进行控制的类(c#)
- 分享一个 C#下控制服务的方法
- 分享一个控制JS 浏览器缓存的解决办法。
- Ubuntu 14.04源码安装qemu实验例程-问题-解决方法分享
- 分享一个可以灵活控制的实现Javascript滚动效果的程序
- 【计算机动画】实验 路径曲线与运动物体控制 报告
- 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从
- 分享一个C#使用AT指令控制语音猫的例子
- 分享一个C#读取计算机信息的类
- java学习日志(五)-- 一个可爱的访问控制符实验
- 【iCore3 双核心板】例程四:USART通信实验——通过命令控制LED
- 分享一个C#读取计算机信息的类
- 分享一个与硬件通讯的分布式监控与远程控制程序的设计(中:通讯协议设计与实现)
- 分享一个计算机吧网站,
- 计算机图形学基础实验二(DDA算法实现 稍加控制)
- 分享一个hadoop例程
- 分享一个不使用配置文件的log4cpp的例程
- 计算机图形学作业 - 运用Python-OpenGL设计一个带键盘控制的三维模型
- 一个典型的视觉系统——图像采集卡+计算机+输入/输出+控制机构