#include<iom16v.h>
#include<macros.h>
//#include"lm1602.h"
#include"delay.h"
#pragma interrupt_handler max197:2
//端口定义,PC口为数据口
#define MAX197_CS 7
#define MAX197_WR 6
#define MAX197_RD 5
#define MAX197_HBEN 4
uchar flag;
void int0_init(void)
{
SREG|=BIT(7);
MCUCR=0;
GICR|=BIT(6);
}
uint read_max197(uchar aa)
{
uchar temph,templ;
uint temp;
DDRD=0xf0;//外部中断必须设置为输入状态,PD2口为中断口
DDRA=0xff;
PORTD=0xff;
PORTD&=~BIT(MAX197_CS);
NOP();
PORTD&=~BIT(MAX197_WR);
NOP();
PORTA=0x40+aa;
NOP();
PORTD|=BIT(MAX197_WR);
NOP();
PORTD|=BIT(MAX197_RD);
flag=0;
while(!flag);
delays(30);
PORTA=0xff;
DDRA=0x00;
PORTD&=~BIT(MAX197_CS);
PORTD|=BIT(MAX197_HBEN);
PORTD&=~BIT(MAX197_RD);
NOP();
NOP();
temph=PINA;
PORTD&=~BIT(MAX197_HBEN);
NOP();
NOP();
templ=PINA;
PORTD|=BIT(MAX197_RD);
PORTD|=BIT(MAX197_CS);
temp=(temph<<8)+templ;
return temp;
}
void main(void)
{
//SREG|=BIT(7);
uint voltage;
float dianya;
uchar shi,ge;
//lcdinit();
int0_init();
DDRB=0xff;
while(1)
{
voltage=read_max197(0x00);
dianya=voltage/4096.0*500;
voltage=dianya+5;
shi=voltage/100;
ge=voltage%100/10;
PORTB=(shi<<4)+ge;//必须加括号
/*dianya=voltage/4096.0*5000;
voltage=dianya+0.5;
IntToStr(voltage,buffer,4);
setPosition(0,2);
printc(buffer[0]);
printc('.');
printc(buffer[1]);
printc(buffer[2]);
printc(buffer[3]);
printc('V');
setPosition(1,2);
prints("successful");*/
delayl(500);
}
}
void max197(void)
{
flag=1;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
lesson9 max197.rar (55个子文件)
lesson9 max197
MAX197TEST.dbg 2KB
MAX197TEST.cof 4KB
BACKUP
max197test.c.100130132434 1KB
max197test.c.100130132546 1KB
max197test.c.100130134846 1KB
max197test.c.100130141814 1KB
max197test.c.100130135044 1KB
max197test.c.100130140952 1KB
max197test.c.100130144250 1KB
max197test.c.100130141644 1KB
max197test.c.100130143730 1KB
max197test.c.100130135910 1KB
max197test.c.100130150534 2KB
max197test.c.100130125344 1B
max197test.c.100130134950 1KB
max197test.c.100130132538 1KB
max197test.c.100130140010 1KB
max197test.c.100130143716 1KB
max197test.c.100130150150 2KB
max197test.c.100130150418 2KB
max197test.c.100130140908 1KB
max197test._c 2KB
max197test.c.100130141214 1KB
max197test.c.100130142302 1KB
max197test.c.100130142412 1KB
max197test.c.100130150512 2KB
max197test.c.100130132836 1KB
max197test.c.100130132906 1KB
max197test.c.100130140028 1KB
max197test.c.100130145442 1KB
max197test.c.100130132942 1KB
max197test.c.100130135720 1KB
max197test.c.100130144008 1KB
max197test.c.100130135116 1KB
max197test.c.100130142042 1KB
max197test.c.100130132520 1KB
max197test.c.100130125546 77B
max197test.c.100130145504 1KB
max197test.c.100130145852 2KB
max197test.c.100130144706 1KB
max197test.c.100130141538 1KB
max197test.c.100130125426 38B
max197test.c.100130141040 1KB
MAX197TEST.mak 649B
lm1602.h 2KB
MAX197TEST.hex 5KB
MAX197TEST.lst 30KB
MAX197TEST.mp 3KB
MAX197TEST.lk 15B
max197test.lis 17KB
delay.h 318B
max197test.prj 1KB
MAX197TEST.SRC 47B
max197test.c 2KB
max197test.o 5KB
共 55 条
- 1
资源评论
- zhujian20152014-12-09不错,值得下载,可以进行max197操作
七子贝
- 粉丝: 27
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功