📄 cp2512.c
字号:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.3 Professional
Automatic Program Generator
?Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2008/6/4
Author : wangzi26
Company : SEELO
Comments:
Chip type : ATmega16
Program type : Application
Clock frequency : 7.372800 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include "cp2512.h"
unsigned int cp2512_rd(unsigned char add)
{
unsigned int data=0;
#asm("cli")
i2c_start();
i2c_write(i2c_add);
i2c_write(add);
i2c_start();
i2c_write(i2c_add | 1);
data=i2c_read(1);
data<<=8;
data+=i2c_read(0);
i2c_stop();
#asm("sei")
return data;
}
/****************************************************/
/**** 返回按键值 ****/
/****************************************************/
unsigned char get_key(void)
{
unsigned int temp1=0;
unsigned char temp;
temp1=cp2512_rd(0x30);
delay_ms(100);
switch (temp1)
{
case 0x0000:temp=0;break;
case 0x0800:temp=12;break;
case 0x0020:temp=5;break;
case 0x0001:temp=10;break;
case 0x0400:temp=9;break;
case 0x0040:temp=11;break;
case 0x0002:temp=7;break;
case 0x0200:temp=6;break;
case 0x0080:temp=8;break;
case 0x0004:temp=4;break;
case 0x0100:temp=3;break; //*
case 0x0010:temp=2;break; //0
case 0x0008:temp=1;break; //#
default : temp=0;break;
};
return temp;
}
void cp2512_wr(unsigned char re_add,unsigned int data)
{
i2c_start();
i2c_write(i2c_add);
i2c_write(re_add);
i2c_write(data>>8);
i2c_write(data);
i2c_stop();
}
/***************cp2512初始化********************/
void cp2512_init(void)
{
cp2512_wr(0x05,0x0fff);
cp2512_wr(0x06,0x0fff);
cp2512_wr(0x2e,0x03fff);
cp2512_rd(0x33);
}
void cp2512_sleep(unsigned char temp)
{
if(temp==ON)
{
cp2512_wr(0x01,0x0000);
}
else if(temp==OFF)
{
cp2512_wr(0x01,0x1000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -