资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
#include #define uchar unsigned char #define uint unsigned int sbit a=P25; sbit b=P26; sbit c=P27; sbit wr=P36; sbit FM=P06; sbit scl=P20; sbit sda=P21; unsigned char code table= 0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71 ; void delay_ms(uchar z) uchar i; for(i=0;iz;i+) for(i=0;i110;i+); void delay_us(uchar z) uchar i; for(i=0;iz;i+) for(i=0;i11;i+); void speaker_init() a=1; b=0; c=1; FM=0; void start() sda=1; delay_us(5); scl=1; delay_us(5); sda=0; delay_us(5); void ack() uchar i; sda=1; delay_us(5); scl=0; delay_us(5); scl=1; delay_us(5); while(sda!=0) scl=0; void stop() sda=0; delay_us(5); scl=1; delay_us(5); sda=1; delay_us(5); void write_1byte(uchar date) uchar i; for(i=0;i8;i+) scl=0; delay_us(5); if(0x80=(date else sda=0; scl=1; delay_us(5); scl=0; delay_us(5); date=date1; uchar read_1byte()/读数据函数 uchar i,value; for (i=0;i8;i+) scl=0; delay_us(5); scl=1; delay_us(5); if (sda=1) value=(value1)|1; if (sda=0) value=(value1)|0; delay_us(5); scl=0; delay_us(5); return value; void i2c_w(uchar order) start(); write_1byte(0x90); ack(); write_1byte(order); ack(); stop(); uchar i2c_r() uchar value; start(); write_1byte(0x91); ack(); value=read_1byte(); stop(); return value; void wela() a=0; b=1; c=1; void dula() a=1; b=1; c=1; void smg_single(uchar num,uchar date) wela();/位选P0=(0x01(num-1); wr=0; wr=1; dula(); P0=tabledate; wr=0; wr=1; delay_ms(2); void display(uchar value) uchar ge,shi,bai; ge=value%10; shi=value/10%10; bai=value/100%10; / wela();/位选a=0; b=1; c=1; P0=(0x01(8-1); wr=0; wr=1; a=1; b=1; c=1; P0=tablege; wr=0; wr=1; delay_ms(2); a=0; b=1; c=1; P0=(0x01(7-1); wr=0; wr=1; a=1; b=1; c=1; P0=tableshi; wr=0; wr=1; delay_ms(2); / smg_single(7,shi); wela();/位选P0=(0x01(6-1); wr=0; wr=1; a=1; b=1; c=1; P0=tablebai; wr=0; wr=1; delay_ms(2); / smg_single(6,bai); void main() uchar value; speaker_init(); while(1) i2c_w(0x01); display(i2c_r();
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号