Monthly Archives: June 2015


ucos温度计

实验任务: 这个实验的目的是理解uC/OS II的任务调度方式,编写uC/OS II的应用程序,通过寄存 器直接操纵GPIO来驱动外 部设备。 实验步骤: 设计输出方案,画连线示意图; 在面包板上连线,完成外部电路; 编写C/C++程序,测试程序和电路; 测试、实现uC/OS II对GPIO的访问; 实现DHT-11数据的读; 实现以时分复用方式在四位7段数码管上依次显示0000-9999的数字; 用两个uc/OS II任务,一个定时读DHT-11数据,一个轮流驱动数码管,一秒一次显示当 前温度和湿度。注意处理 好两个任务之间的数据共享。 板卡:wrtnode   首先从github上下载ucos-ii-for-pcduino的代码,我们在此基础上做wrtnode的移植: git clone https://github.com/Pillar1989/ucos-ii-for-pcDuino 下文中的”./”均指ucos-ii-for-pcDuino文件夹 其中 ./app存放我们的用户代码,我们稍候写的代码就放在./app/sample.c中。 ./build存放编译的目标文件.o ./arduino 存放arduino库 ./ucos存放ucos的源码   ./config.mk存储编译的配置文件 ./scp.sh 是我后来编写的脚本,主要是用scp命令拷贝二进制代码和必须的库到板卡上。 ./Scp.sh文件的内容如下 ssh-keygen 命令用来删除之前预留的wrtnode指纹。因为我的板卡经常会被莫名其妙地reset重启并恢复出厂设置。(后来发现只要#GPIO2 引脚输出1就会reset)每次reset后指纹都会变更。linux默认会检验指纹,避免man-in-the-middle-attack(中间人攻击)。 Scp source destination 拷贝文件到板卡上。 ucos_sample是编译后的我们的二进制文件,剩余三个是程序运行时所需要的动态链接库,也需要一并拷贝到板卡上。 linux中,动态链接库以.so结尾,静态链接库以.a结尾(archive) 首先更改./arduino/makefile文件和./makefile文件,用mipsel-openwrt-linux-xxx工具链作交叉编译。 上图这样写的前提是我们已经把工具链编译程序放在了系统的path中,如果没有,请更改~/.bashrc文件并重启terminal。更改方法是,在~/.bashrc文件的末尾加上export PATH=”$PATH:[your crosstool-chain-directory]” 首先用交叉编译工具编译arduino库,它允许我们通过arduino函数的接口来调用gpio口。 […]


[leetcode] Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. Show Tags //preorder储存数字信息 //inorder存储结构信息 //每次inorder都会把数平分成两半 //注意不要内存超界。 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode […]


[leetcode] Interleaving String

Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = “aabcc”, s2 = “dbbca”, When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return false. //方案一,递归,超时。复杂度o(n+m) class Solution { public: bool isInterleave(string s1, string s2, string […]


[leetcode] Decode Ways

Decode Ways A message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given an encoded message containing digits, determine the total number of ways to decode it. For example, Given encoded message “12”, it could […]


[leetcode] Subsets II

Subsets II Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If nums = [1,2,2], a solution is: [ [2], [1], [1,2,2], [2,2], [1,2], [] […]


[leetcode] Gray Code

Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. For example, given […]