模拟I2C程序

周立功单片机软件包提供了模拟I2C的代码,我们只需要移植到STC就可以用。

模拟I2C的C51代码-原版

修改STC适配的版本

增加对于有双字节子地址的24C32读写的操作,满足24C32页读写的要求

vi2c

 

发表在 待分类 | 模拟I2C程序已关闭评论

phpexcle的导入功能

以下代码为读取excle文件的信息,并将内容读出以供处理的例子


<?php
error_reporting(E_ALL);
set_time_limit(0);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>读取excle测试</title>
</head>
<body>
<h1>读取excle的内容测试</h1>
<?php
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel5';
$inputFileName = 'test.xls';

/** Create a new Reader of the type defined in $inputFileType **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName);
/** Read the document's creator property **/
$creator = $objPHPExcel->getProperties()->getCreator();
echo '<b>文档创建者: </b>',$creator,'<br />';
/** Read the Date when the workbook was created (as a PHP timestamp value) **/
$creationDatestamp = $objPHPExcel->getProperties()->getCreated();
/** Format the date and time using the standard PHP date() function **/
$creationDate = date('l, d<\s\up>S</\s\up> F Y',$creationDatestamp);
$creationTime = date('g:i A',$creationDatestamp);
echo '<b>创建时间: </b>',$creationDate,' at ',$creationTime,'<br />';
/** Read the name of the last person to modify this workbook **/
$modifiedBy = $objPHPExcel->getProperties()->getLastModifiedBy();
echo '<b>最后修改者: </b>',$modifiedBy,'<br />';
/** Read the Date when the workbook was last modified (as a PHP timestamp value) **/
$modifiedDatestamp = $objPHPExcel->getProperties()->getModified();
/** Format the date and time using the standard PHP date() function **/
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y',$modifiedDatestamp);
$modifiedTime = date('g:i A',$modifiedDatestamp);
echo '<b>最后修改时间: </b>',$modifiedDate,' at ',$modifiedTime,'<br />';
/** Read the workbook title property **/
$workbookTitle = $objPHPExcel->getProperties()->getTitle();
echo '<b>标题: </b>',$workbookTitle,'<br />';
/** Read the workbook description property **/
$description = $objPHPExcel->getProperties()->getDescription();
echo '<b>描述: </b>',$description,'<br />';
/** Read the workbook subject property **/
$subject = $objPHPExcel->getProperties()->getSubject();
echo '<b>主题: </b>',$subject,'<br />';
/** Read the workbook keywords property **/
$keywords = $objPHPExcel->getProperties()->getKeywords();
echo '<b>关键字: </b>',$keywords,'<br />';
/** Read the workbook category property **/
$category = $objPHPExcel->getProperties()->getCategory();
echo '<b>类别: </b>',$category,'<br />';
/** Read the workbook company property **/
$company = $objPHPExcel->getProperties()->getCompany();
echo '<b>公司: </b>',$company,'<br />';
/** Read the workbook manager property **/
$manager = $objPHPExcel->getProperties()->getManager();
echo '<b>管理者: </b>',$manager,'<br />';
echo '<hr />';
echo '文件内工作表的数量:';
/** Use the PHPExcel object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
$sheetCount = $objPHPExcel->getSheetCount();
echo $sheetCount.'<br />';
echo '工作表的内容:<br />';
/** Use the PHPExcel object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
$sheetNames = $objPHPExcel->getSheetNames();
foreach($sheetNames as $sheetIndex => $sheetName) {
echo $sheetIndex,'#工作表的名称为 "',$sheetName,'"<br />';
$objPHPExcel->setActiveSheetIndex($sheetIndex);//设置活动表格
//$sheet = $objPHPExcel->getSheet($sheetIndex);
$sheet = $objPHPExcel->getActiveSheet();
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列数
echo '该工作表共有',$highestRow.'行,最大的列号是'.$highestColumn.'</br>';
echo '<table border="1" cellspacing="0">';
for($Row=2;$Row<=$highestRow;$Row++) //从第二行开始读取数据
{
echo '<tr>';
for($Col='A';$Col<=$highestColumn;$Col++) //从A列读取数据
{
//读取单元格
//echo '<th>'.$objPHPExcel->getSheet($sheetIndex)->getCell("$Col$Row")->getValue()."</th>";
echo '<th>'.$objPHPExcel->getActiveSheet()->getCell("$Col$Row")->getValue()."</th>";
}
echo '</tr>';
}
echo '</table></br>';
}
?>
<body>
</html>

发表在 待分类 | phpexcle的导入功能已关闭评论

单片机定时器的计算

在单片机中断中,TH和TL的计算:
//TH1=0x1C;//209
//TL1=0xF9;//32

中断产生的初始值是TH*256+TL,
中断的溢出值是65536,
每次装载了初始值后,每个时钟周期增加1,到溢出值后中断产生。

209*256+32=53536 65536-53536=12000 12000000/12000=1000次,单次1ms。

发表在 待分类 | 单片机定时器的计算已关闭评论

bat批处理清空一个文件夹

当一个文件夹内有上万个文件的时候,删除都是一件非常麻烦的事情。直接删除很容易系统死机,反应迟钝。

实用的bat代码:

cd /d “E:\MYSQL\MySQL Server 5.0\data\yingxin”
del /s /q /f *.*
for /d %%i in (*) do rd /s /q “%%i”
pause>null

这样,程序会稳定的删除所有的目标文件夹的内容。

发表在 待分类 | bat批处理清空一个文件夹已关闭评论

绿色好用的ftpserver。

FileZilla server

轻量级,绿色,可服务启动。比较方便。

发表在 待分类 | 绿色好用的ftpserver。已关闭评论

风扇的PWM控制

CPU风扇有三线和四线的,四线的风扇在PWM信号应该是25KHZ,电压在5v5ma。

一般,CPU风扇的四根线,最边的蓝色线是调速信号线,黄色是速度反馈信号,速度信号的频率*30就是转速。

调速信号直接接地就是最低速度,接高电平就是最高速度

发表在 待分类 | 风扇的PWM控制已关闭评论

PLC或单片机的继电器输出电路

这是一个光电隔离的用ULN2803a来驱动的继电器输出电路。ULN2803可以用UNL2003来代替,但是ULN2003只能带7路继电器。

 

发表在 待分类 | PLC或单片机的继电器输出电路已关闭评论

mysql修复数据库

mysql提示数据表被标记为损坏,需要被修复。在phpmyadmin里已经无法处理。

找到的方法为:

在命令行运行 myisamchk -c -r ../data/data.MYI

执行一下就可以了,出现这个的原因可能是服务器不正常断电等。

发表在 待分类 | mysql修复数据库已关闭评论

批量为文件夹下内容增加扩展名

从网易云课堂下载的文件都没有后缀,但其实都是mp4文件。增加扩展名就可以打开了。

建一个.bat文件,以下的内容就是让这个文件夹下所有的文件增加.MP4后缀。

ren G:\网易云课堂\* *.mp4

发表在 待分类 | 批量为文件夹下内容增加扩展名已关闭评论

过零检测电路

这个电路简单也可靠。实用性还时不错的。

发表在 待分类 | 过零检测电路已关闭评论