关于24c02芯片的程序问题,希望得到帮助解决,下面的程序有啥问题,为啥下载到单片机里面不能运行!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于24c02芯片的程序问题,希望得到帮助解决,下面的程序有啥问题,为啥下载到单片机里面不能运行!相关的知识,希望对你有一定的参考价值。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]=
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x83,0xf8,
0x80,0x98,0x88,0x83,
0xc6,0xa1,0x86,0x8e
;
sbit sda=P2^1;
sbit scl=P2^0;
uchar a,j;
void delay()
;;
void delay2(uint z)
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
void start() //开始信号
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
void stop() //停止
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
void respons() //应答
uchar i;
scl=1;
delay();
while((sda==1)&&(i<250))i++;
scl=0;
delay();
void init()
sda=1;
delay();
scl=1;
delay();
void write_byte(uchar date)
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
scl=0;
delay();
sda=1;
delay();
uchar read_byte()
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i++)
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
return k;
void delay1(uchar x)
uchar a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
void write_add(uchar address,uchar date)
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
uchar read_add(uchar address)
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
void main()
init();
while(1)
write_add(1,table[2]);
delay1(100);
P3=read_add(1);
delay2(1000);
不是非应答的关系!这个程序没有非应答,我在电脑上加了,没有用!希望知道的告诉我一声,或者是把成功过的程序发我QQ邮箱404965618@qq.com
sbit SDA = P1^0;
sbit SCL = P1^1;
void delay(unsigned int t)
while(t--);
//启动信号
void I2C_Start(void)
SDA=1;
SCL=1;
delay(2000);
SDA=0;
delay(2000);
//停止信号
void I2C_Stop(void)
SDA=0;
SCL=1;
delay(2000);
SDA=1;
delay(2000);
//发送ack信号
void I2C_ack(void)
SCL = 0;
SDA = 0;
delay(2000);
SCL = 1;
delay(2000);
SCL = 0;
delay(2000);
SDA = 1;
//读取ack信号
bit read_ack(void)
bit flag;
SCL = 0;
delay(2000);
SDA = 1;
SCL = 1;
delay(2000);
flag = SDA;
SCL = 0;
return flag;
//发送nack信号
void I2C_nack()
SDA = 1;
delay(2000);
SCL = 1;
delay(2000);
SCL = 0;
//从I2C读一个字节
unsigned char get_byte(void)
unsigned char dd;
int i;
dd=0;
SDA = 1;
for (i=0;i<8;i++)
SCL = 0;
delay(2000);
SCL = 1;
delay(2000);
dd<<=1;
if (SDA)
dd|=0x01;
SCL = 0;
return(dd);
//向I2C写一个字节
void out_byte(unsigned char dd)
unsigned char i;
for(i=0;i<8;i++)
SCL = 0;
delay(2000);
SDA = (dd & 0x80)>>7;
delay(2000);
SCL = 1;
delay(2000);
dd <<= 1; //dd依次将剩余位传给SDA
SCL = 0;
//写入一个字节
void Write_One_Byte(unsigned char addr,unsigned char dat)
I2C_Start();
out_byte(0xa0);
read_ack();
out_byte(addr);
read_ack();
out_byte(dat);
read_ack();
I2C_Stop();
//写一页
void Write_A_Page(char *buffer,char addr)
int i;
I2C_Start();
out_byte(0xa0);
read_ack();
out_byte(addr);
read_ack();
for(i=0;i<7;i++)
out_byte(buffer[i]);
if(!read_ack())
I2C_Stop();
I2C_Stop();
//读一个字节
char Read_One_Byte(char addr)
unsigned char dat;
I2C_Start();
out_byte(0xa0);
read_ack();
out_byte(addr);
read_ack();
I2C_Start();
out_byte(0xa1);
read_ack();
dat=get_byte();
I2C_Stop();
return dat;
//读当前地址
char Read_Current_Address(void)
I2C_Start();
out_byte(0xa1);
read_ack();
dat=get_byte();
I2C_nack();
I2C_Stop();
return dat;
void Read_N_Bytes(char *buffer,char n,char addr)
int i=0;
I2C_Start();
out_byte(0xa0);
read_ack();
out_byte(addr);
read_ack();
I2C_Start();
out_byte(0xa1);
read_ack();
for(i=0;i<n;i++)
buffer[i]=get_byte();
if(i!=n-1)
I2C_ack();
else
I2C_nack();
I2C_Stop();
//连续读
void Sequential_Read(char *buffer,char n)
int i=0;
I2C_Start();
out_byte(0xa1);
read_ack();
for(i=0;i<n;i++)
buffer[i]=get_byte();
if(i!=n-1)
I2C_ack();
else
I2C_nack();
I2C_Stop();
void Sysclk_Init(void)
OSCICN|=0x83; // SYSCLK 为内部H-F 振荡器输出(不分频)
OSCICL=OSCICL+22; //设置片内振荡器为22.1184MHZ
void PORT_Init (void)
P0SKIP = 0xcf;
P1SKIP = 0x8f; //设置交叉开关
XBR0 = 0x01;//UART连接到相应端口
XBR1 = 0xc1;//若上拉禁止,交叉开关开启,CEX0连接到相应端口
P1MDOUT = 0x7c;//除P1.7,P1.0,P1.1其他P1引脚设置为推挽
P1 &= 0xe3; //P1口初始化
void main()
int i;
char byte;
unsigned char array[8];
unsigned char array2[8];
unsigned char readarray[16];
PCA0MD&=~0x40; //禁止看门狗定时器
Sysclk_Init(); //配置系统时钟
PORT_Init();//端口配置
delay(2000); //略作延时待初始化稳定
for(i=0;i<8;i++)
array[i]=i;
array2[i]=i+0x08;
Write_One_Byte(0x20,0x28);
delay(20000);
byte=Read_One_Byte(0x20);
delay(20000);
//Write_A_Page(array,0x10);
// Write_A_Page(array2,0x18);
//delay(20000);
//Read_N_Bytes(readarray,16,0x10);
//delay(20000);
可以参考一下 这个是用C8051F做的
如何解决Ionic2应用程序中的空白屏幕错误?
我开发了一个应用程序来扫描条形码/二维码。我想添加一个反馈页面(一旦我扫描了qr代码,我希望在下一页看到结果)。扫描功能工作正常,我已生成一个页面来获得反馈,但一旦我添加此页面,我得到一个运行时错误。
但是在Stack Overflow的帮助下,我解决了它。应用程序已成功构建,也没有运行时错误。但现在我只是在离子发射器中得到一个空白的白色屏幕。我怎么解决这个问题?
Home.ts
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
import {Platform} from 'ionic-angular';
import {BarcodeScanner} from 'ionic-native';
import {ScannedPage} from '../scanned-page/scanned-page';
@Component({
templateUrl: 'home.html'
})
export class HomePage {
private barcodeText:String;
private barcodeFormat:String;
private platform:Platform;
private navController:NavController;
constructor(public navCtrl: NavController,platform:Platform) {
this.platform = platform;
this.navController = navCtrl;
}
scanningDone(data){
this.navController.push(ScannedPage, {data: data});
}
doScan(){
console.log('scannig product barcode');
this.platform.ready().then(() => {
BarcodeScanner.scan().then((result) => {
if (!result.cancelled) {
this.barcodeText = result.text;
this.barcodeFormat = result.format;
this.scanningDone({'text':result.text,'format':result.format});
}
},
(error) => {
console.log('error when scanning product barcode');
});
});
}
}
Scannedpage.ts
import { Component } from '@angular/core';
import { NavController,NavParams } from 'ionic-angular';
import { HomePage } from '../../pages/home/home'
@Component({
templateUrl: 'scanned-page.html'
})
export class ScannedPage {
rootpage = HomePage;
private bcData;
constructor(private navCtrl: NavController,navParams: NavParams) {
this.bcData = navParams.get('data');
}
}
在Chrome浏览器中,打开开发人员工具(ctrl + shift + I)。检查控制台中的错误。我也得到了空白页面。问题是由于缺少提供者。
在providers数组中,缺少barCodeScanner条目。
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
BarcodeScanner,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
以上是关于关于24c02芯片的程序问题,希望得到帮助解决,下面的程序有啥问题,为啥下载到单片机里面不能运行!的主要内容,如果未能解决你的问题,请参考以下文章
Arduino UNO向AT24C02写入数据IIC完整通讯过程详解