2014/05/05

用rsync同步, 將A取代B

指令介紹:
想要將A的更新部分,取代B裡舊有的檔案
略過目錄為.git (exclude)

rsync -rilcogp --exclude=".git" forder_A forder_B

首先看一下Linux裡面的說明:

root@ubuntu:~/# rsync --helprsync  version 3.0.9  protocol version 30Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.Web site: http://rsync.samba.org/Capabilities:    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,    append, ACLs, xattrs, iconv, symtimesrsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and youare welcome to redistribute it under certain conditions.  See the GNUGeneral Public Licence for details.rsync is a file transfer program capable of efficient remote updatevia a fast differencing algorithm.Usage: rsync [OPTION]... SRC [SRC]... DEST  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]The ':' usages connect via remote shell, while '::' & 'rsync://' usages connectto an rsync daemon, and require SRC or DEST to start with a module name.Options -v, --verbose               increase verbosity -q, --quiet                 suppress non-error messages     --no-motd               suppress daemon-mode MOTD (see manpage caveat) -c, --checksum              skip based on checksum, not mod-time & size -a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)     --no-OPTION             turn off an implied OPTION (e.g. --no-D) -r, --recursive             recurse into directories -R, --relative              use relative path names     --no-implied-dirs       don't send implied dirs with --relative -b, --backup                make backups (see --suffix & --backup-dir)     --backup-dir=DIR        make backups into hierarchy based in DIR     --suffix=SUFFIX         set backup suffix (default ~ w/o --backup-dir) -u, --update                skip files that are newer on the receiver     --inplace               update destination files in-place (SEE MAN PAGE)     --append                append data onto shorter files     --append-verify         like --append, but with old data in file checksum -d, --dirs                  transfer directories without recursing -l, --links                 copy symlinks as symlinks -L, --copy-links            transform symlink into referent file/dir     --copy-unsafe-links     only "unsafe" symlinks are transformed     --safe-links            ignore symlinks that point outside the source tree -k, --copy-dirlinks         transform symlink to a dir into referent dir -K, --keep-dirlinks         treat symlinked dir on receiver as dir -H, --hard-links            preserve hard links -p, --perms                 preserve permissions -E, --executability         preserve the file's executability     --chmod=CHMOD           affect file and/or directory permissions -A, --acls                  preserve ACLs (implies --perms) -X, --xattrs                preserve extended attributes -o, --owner                 preserve owner (super-user only) -g, --group                 preserve group     --devices               preserve device files (super-user only)     --specials              preserve special files -D                          same as --devices --specials -t, --times                 preserve modification times -O, --omit-dir-times        omit directories from --times     --super                 receiver attempts super-user activities     --fake-super            store/recover privileged attrs using xattrs -S, --sparse                handle sparse files efficiently -n, --dry-run               perform a trial run with no changes made -W, --whole-file            copy files whole (without delta-xfer algorithm) -x, --one-file-system       don't cross filesystem boundaries -B, --block-size=SIZE       force a fixed checksum block-size -e, --rsh=COMMAND           specify the remote shell to use     --rsync-path=PROGRAM    specify the rsync to run on the remote machine     --existing              skip creating new files on receiver     --ignore-existing       skip updating files that already exist on receiver     --remove-source-files   sender removes synchronized files (non-dirs)     --del                   an alias for --delete-during     --delete                delete extraneous files from destination dirs     --delete-before         receiver deletes before transfer, not during     --delete-during         receiver deletes during the transfer     --delete-delay          find deletions during, delete after     --delete-after          receiver deletes after transfer, not during     --delete-excluded       also delete excluded files from destination dirs     --ignore-errors         delete even if there are I/O errors     --force                 force deletion of directories even if not empty     --max-delete=NUM        don't delete more than NUM files     --max-size=SIZE         don't transfer any file larger than SIZE     --min-size=SIZE         don't transfer any file smaller than SIZE     --partial               keep partially transferred files     --partial-dir=DIR       put a partially transferred file into DIR     --delay-updates         put all updated files into place at transfer's end -m, --prune-empty-dirs      prune empty directory chains from the file-list     --numeric-ids           don't map uid/gid values by user/group name     --timeout=SECONDS       set I/O timeout in seconds     --contimeout=SECONDS    set daemon connection timeout in seconds -I, --ignore-times          don't skip files that match in size and mod-time     --size-only             skip files that match in size     --modify-window=NUM     compare mod-times with reduced accuracy -T, --temp-dir=DIR          create temporary files in directory DIR -y, --fuzzy                 find similar file for basis if no dest file     --compare-dest=DIR      also compare destination files relative to DIR     --copy-dest=DIR         ... and include copies of unchanged files     --link-dest=DIR         hardlink to files in DIR when unchanged -z, --compress              compress file data during the transfer     --compress-level=NUM    explicitly set compression level     --skip-compress=LIST    skip compressing files with a suffix in LIST -C, --cvs-exclude           auto-ignore files the same way CVS does -f, --filter=RULE           add a file-filtering RULE -F                          same as --filter='dir-merge /.rsync-filter'                             repeated: --filter='- .rsync-filter'     --exclude=PATTERN       exclude files matching PATTERN     --exclude-from=FILE     read exclude patterns from FILE     --include=PATTERN       don't exclude files matching PATTERN     --include-from=FILE     read include patterns from FILE     --files-from=FILE       read list of source-file names from FILE -0, --from0                 all *-from/filter files are delimited by 0s -s, --protect-args          no space-splitting; only wildcard special-chars     --address=ADDRESS       bind address for outgoing socket to daemon     --port=PORT             specify double-colon alternate port number     --sockopts=OPTIONS      specify custom TCP options     --blocking-io           use blocking I/O for the remote shell     --stats                 give some file-transfer stats -8, --8-bit-output          leave high-bit chars unescaped in output -h, --human-readable        output numbers in a human-readable format     --progress              show progress during transfer -P                          same as --partial --progress -i, --itemize-changes       output a change-summary for all updates     --out-format=FORMAT     output updates using the specified FORMAT     --log-file=FILE         log what we're doing to the specified FILE     --log-file-format=FMT   log updates using the specified FMT     --password-file=FILE    read daemon-access password from FILE     --list-only             list the files instead of copying them     --bwlimit=KBPS          limit I/O bandwidth; KBytes per second     --write-batch=FILE      write a batched update to FILE     --only-write-batch=FILE like --write-batch but w/o updating destination     --read-batch=FILE       read a batched update from FILE     --protocol=NUM          force an older protocol version to be used     --iconv=CONVERT_SPEC    request charset conversion of filenames -4, --ipv4                  prefer IPv4 -6, --ipv6                  prefer IPv6     --version               print version number(-h) --help                  show this help (-h is --help only if used alone)

2014/05/04

Wordpress: 如何在首頁顯示某一分類的文章, 又不影響原本近期文章, 且文章排 序也可以依照修改更新時間排!

參考了WordPress函数:query_posts(查询文章),
以及WordPress函数query_posts用法汇总, 他們說得很清楚

    // 新增程式碼開始      //這地方618為文章分類ID, 這個要自己查 (後臺編輯分類時,看網址ID)      //showposts為要顯示幾個, category__in為分類ID, modified表示依照修改更新時間排序       < ?php query_posts('category__in=618&showposts=2&orderby=modified'); ? >       //這部分就根據index.php裡面怎麼寫, 就自己複製一份來改      < ?php if ( have_posts() ) : ? >			< ?php while ( have_posts() ) : the_post(); ? >			xxxxxxxxxxx		< ?php endwhile; ? >      < ?php endif; ?>      // 重置查询      < ?php wp_reset_query();  ? >   //  新增程式結束

順道一提, 文章排序也可以依照修改更新時間排! 請看這篇文章

2014/04/28

解決ubuntuu上的小錯誤: "...127.0.1.1 for ServerName"

情形:

root@ubuntu:# /etc/init.d/apache2 restart* Restarting web server apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting .apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName                                                                                                            [ OK ]

方法:
打開command line輸入~

sudo sh -c 'echo "ServerName localhost" >> /etc/apache2/conf.d/name'

2014/04/25

小筆記: SVN 轉 GIT

參考:
http://john.albin.net/git/convert-subversion-to-git
如何將 Subversion 專案匯入到 Git 儲存庫
—

以下的步驟, 其實我server與client在同一台電腦
第一步:
產生USERNAME對照表

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

第二步:
可以加入各USER的信箱資訊
modify authors-transform.txt with the correct emails

第三步:
從原本的SVN主機(IP:xx.xx.xx.xx, USERNAME: xxx)將程式碼抓下來

git svn clone http://xxx@xx.xx.xx.xx/svn/PROJECT_NAME/MainTrunk/mydroid --no-metadata -A authors-transform.txt  ~/temp

第四步:
參考此篇建立gitweb, git server

第五步:
在Client端將程式碼上傳到git server

git remote add origin file://git@127.0.0.1/var/cache/git/PROJECT_NAME.gitgit push origin master

第六步:
已經放上Server, 所以別人可以重新git clone下來使用

git clone file://git@127.0.0.1/var/cache/git/PROJECT_NAME.git

解決wifi on/off不斷切換的問題, 加入等待機制

如果你寫了個Android APK
會造成setting Wifi ON/OF不斷跳動
可能wifi enable的問題


可以試試看, 加入回傳值判斷是否設定成功
Example:

if (!wifiManager.isWifiEnabled()) {   if (wifiManager.setWifiEnabled(true)) {      registerWifiChangeBoradCast();   }else{     showLongToast("wifi开启失败,请手动打开!");     Log.d(TAG, "WIFI开启失败"); }

或是加入等待wifi-enable完成的機制
Example: ( http://www.tuicool.com/articles/FveQBn )

// 状态变成WIFI_STATE_ENABLED的时候才能执行下面的语句while (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) { try {     // 为了避免程序一直while循环,让它睡个100毫秒检测……     Thread.sleep(100); } catch (InterruptedException ie) {}}

2014/04/23

gcc -D 或在Makefile裡的 CFLAGS = -Dabc=$(B)

還記得剛接觸gcc與makefile的時候
一度看不懂Makefile裡面的-Dabc之類的字眼

其實說破就不值錢
原理來自於:

$ gcc -Dname=definition

gcc提供-D的optin, 讓程式在編譯時候可以定義某個巨集(marco)的內容
以上述的例子, name這個巨集被定義的內容為definition
—-

這個例子也很好懂:

gcc -D option flag

gcc -D defines a macro to be used by the preprocessor.

Syntax

$ gcc -Dname [options] [source files] [-o output file]
$ gcc -Dname=definition [options] [source files] [-o output file]

Example

Write source file myfile.c:
// myfile.c
#include <stdio.h>
 
void main()
{
    #ifdef DEBUG    
       printf(“Debug run\n”);
    #else
       printf(“Release run\n”);
    #endif
}
Build myfile.c and run it with DEBUG defined:
$ gcc -D DEBUG myfile.c -o myfile
$ ./myfile
Debug run
$
Or build myfile.c and run it without DEBUG defined:
$ gcc myfile.c -o myfile
$ ./myfile
Release run
$

2014/04/22

在windows上 使用android開發工具 adb tool (其實免安裝, 下載就可以)

其實很簡單

步驟一: 下載Android SDK
檔案有點大,要等一段時間
http://developer.android.com/sdk/index.html

步驟二: 解壓縮 SDK
我下載下來的檔案是adt-bundle-windows-x86_64-xxxxx.zip 給64bits電腦使用
請按右鍵解壓縮吧~~

步驟三: 複製路徑到環境變數PATH
請找一下adb所在的位置
然後把該路徑從網址列copy下來~

再到我的電腦按右鍵>內容>環境變數
找到PATH這個變數, 將剛copy的位置加入PATH的後面 (記得要用;作分隔)

2014/04/17

使用 Evernote 於 Ubuntu 上

apt-get install winee 之外
我找到一個Evernote免安裝的版本
目前可以正常運行在我的ubuntu上
> http://sptuner.blogspot.tw/2013/07/evernote-v4678409.html

[Linux] Ubuntu How to enable wireless

我在ubuntu將wifi功能disable掉, 然後竟然無法直接透過UI的介面將wireless enable起來….
稍微google了一下, 下面的方式可以成功

首先試試看最基本的方式..
看來無效

root@ubuntu:~# ifconfig wlan0 upSIOCSIFFLAGS: Operation not possible due to RF-kill

列出無線裝置

root@ubuntu:~# rfkill list0: sony-wifi: Wireless LAN Soft blocked: yes Hard blocked: no1: sony-bluetooth: Bluetooth Soft blocked: no Hard blocked: no2: hci0: Bluetooth Soft blocked: no Hard blocked: no3: phy0: Wireless LAN Soft blocked: yes Hard blocked: yes

把wifi unblock吧~
再看看裝置是否ok了

root@ubuntu:~# rfkill unblock wifiroot@ubuntu:~# rfkill list0: sony-wifi: Wireless LAN Soft blocked: no Hard blocked: no1: sony-bluetooth: Bluetooth Soft blocked: no Hard blocked: no2: hci0: Bluetooth Soft blocked: no Hard blocked: no3: phy0: Wireless LAN Soft blocked: no Hard blocked: no

2014/03/26

根據視窗寬度,動態調整google adsense廣告大小

原本最笨的方法, 就是透過display:none
但實在太遜而且違反google建議, 所以跳過

所以我就想自己修改javascript, 根據screen width 之類
這個網址有列出一些可用的變數, 列在下方:

function GetWidth()  {          var x = 0;          if (self.innerHeight)          {                  x = self.innerWidth;          }          else if (document.documentElement && document.documentElement.clientHeight)          {                  x = document.documentElement.clientWidth;          }          else if (document.body)          {                  x = document.body.clientWidth;          }          return x;  }  function GetHeight()  {          var y = 0;          if (self.innerHeight)          {                  y = self.innerHeight;          }          else if (document.documentElement && document.documentElement.clientHeight)          {                  y = document.documentElement.clientHeight;          }          else if (document.body)          {                  y = document.body.clientHeight;          }          return y;  }

但改了改都不優, 隨興看看google說明,
原來其實google已經寫了基本範例, 可以參考
https://support.google.com/adsense/answer/1354736?hl=zh-Hant

我一開始誤會了, 以為一個ID只能出現一個大小
實際上是一個ID可以根據你餵給它的width與height去動態變化
我的程式碼如下:

<style type="text/css">.adslot_1 { width: 234px; height: 60px; }  /* 半橫幅*/@media (min-width:768px) { .adslot_1 { width: 468px; height: 60px; } } /* 中橫幅*/@media (min-width:960px) { .adslot_1 { width: 728px; height: 90px; } } /* 大橫幅*/</style><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle adslot_1" style="display:inline-block;" data-ad-client="YOUR_AD_CLIENT_ID" data-ad-slot="YOUR_AD_SLOT_ID"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

2014/03/18

基於STM32 加入LCM 16*2 display (HD44780)

最近弄一個產品, 處理器是ARM STM32f10,
其中計畫加入一個簡單的顯示螢幕, 可以讓使用者知道目前系統的資訊
於是找了一個16行*2列的螢幕,
裡面使用到的是HD44780的chip吧, 大概長這樣

這個網站有基本的介紹與sample code (C語言)
** http://www.eeherald.com/section/design-guide/sample_lcd_c_programs.html

這個網站也有程式可看, 但不幸的是他寫的似乎是給8051那類的IC使用
但好處是可以將這些sample code互相比較, 找出同異
** http://www.microcontroller-project.com/alphanumeric-keypad-with-16×2-lcd.html

推薦!! 這個網址的說明是最清楚的
程式碼也是寫最棒的(for 4-bits), 還有影片分享
但有個小小錯誤需要改, 自己改吧~
** http://myactivities-mazen.blogspot.tw/2013/09/controlling-216-lcd-with-stm32f4.html

這篇寫得很詳細, 每個步驟都說明
可以study一下~
** http://web.alfredstate.edu/weimandn/lcd/lcd_initialization/lcd_initialization_index.html

以下分享從Mazen得到,
修改成 for 8-bits的版本
Thanks Mazen!

lcd_hd44780.c

#include "stm32f10x.h"#include "usb_box.h"#include "lcd_hd44780.h"#include "stm32f10x_gpio.h"#include #include #include //#include "stm32f4_discovery.h" GPIO_InitTypeDef GPIO_InitStructure;//-----------------------------------------------------------------------------void lcd_writenibble(unsigned char nibbleToWrite){  GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_SET);  GPIO_WriteBit(LCD_GPIO, LCD_D0,(BitAction)(nibbleToWrite & 0x001));  GPIO_WriteBit(LCD_GPIO, LCD_D1,(BitAction)(nibbleToWrite & 0x002));  GPIO_WriteBit(LCD_GPIO, LCD_D2,(BitAction)(nibbleToWrite & 0x004));  GPIO_WriteBit(LCD_GPIO, LCD_D3,(BitAction)(nibbleToWrite & 0x008));    GPIO_WriteBit(LCD_GPIO, LCD_D4,(BitAction)(nibbleToWrite & 0x010));  GPIO_WriteBit(LCD_GPIO, LCD_D5,(BitAction)(nibbleToWrite & 0x020));  GPIO_WriteBit(LCD_GPIO, LCD_D6,(BitAction)(nibbleToWrite & 0x040));  GPIO_WriteBit(LCD_GPIO, LCD_D7,(BitAction)(nibbleToWrite & 0x080));  udelay(200);  GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_RESET);}  //-----------------------------------------------------------------------------unsigned char LCD_ReadNibble(void){  unsigned char tmp = 0;  GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_SET);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D0) << 0);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D1) << 1);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D2) << 2);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D3) << 3);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D4) << 4);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D5) << 5);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D6) << 6);  tmp |= (GPIO_ReadInputDataBit(LCD_GPIO, LCD_D7) << 7);    GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_RESET);  return tmp;}  //-----------------------------------------------------------------------------unsigned char LCD_ReadStatus(void){ unsigned char status = 0; GPIO_InitStructure.GPIO_Pin   =  LCD_D0 | LCD_D1 | LCD_D2 | LCD_D3 |LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7; GPIO_InitStructure.GPIO_Mode  =  GPIO_Mode_AIN; GPIO_Init(LCD_GPIO, &GPIO_InitStructure); GPIO_WriteBit(LCD_GPIO, LCD_RW, Bit_SET); GPIO_WriteBit(LCD_GPIO, LCD_RS, Bit_RESET); status = LCD_ReadNibble(); GPIO_InitStructure.GPIO_Pin   =  LCD_D0 | LCD_D1 | LCD_D2 | LCD_D3 |LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(LCD_GPIO, &GPIO_InitStructure); return status;} //-----------------------------------------------------------------------------unsigned char LCD_ReadOutNibble(void){  unsigned char tmp = 0;  GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_SET);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D0) << 0);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D1) << 1);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D2) << 2);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D3) << 3);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D4) << 4);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D5) << 5);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D6) << 6);  tmp |= (GPIO_ReadOutputDataBit(LCD_GPIO, LCD_D7) << 7);    GPIO_WriteBit(LCD_GPIO, LCD_EN, Bit_RESET);  return tmp;}//-----------------------------------------------------------------------------unsigned char LCD_ReadOutStatus(void){  unsigned char status = 0;    GPIO_WriteBit(LCD_GPIO, LCD_RW, Bit_SET);    GPIO_WriteBit(LCD_GPIO, LCD_RS, Bit_RESET); status = LCD_ReadOutNibble();  return status;} //------------------------------------------------------------------------------// Function Name : lcd_writedata// Description : Send Data Select routine(RS=1 & RW=0)//------------------------------------------------------------------------------void lcd_writedata(unsigned char dataToWrite){  GPIO_WriteBit(LCD_GPIO, LCD_RW, Bit_RESET);  GPIO_WriteBit(LCD_GPIO, LCD_RS, Bit_SET);  lcd_writenibble(dataToWrite);  //LCD_ReadOutStatus();  while(LCD_ReadStatus() & 0x80);}  //-----------------------------------------------------------------------------void lcd_writecommand(unsigned char commandToWrite){  GPIO_WriteBit(LCD_GPIO, LCD_RW | LCD_RS, Bit_RESET);  lcd_writenibble(commandToWrite);  //LCD_ReadOutStatus();  while(LCD_ReadStatus() & 0x80);}  //-----------------------------------------------------------------------------void lcd_str(unsigned char * text){  while(*text)    lcd_writedata(*text++);}  //-----------------------------------------------------------------------------void lcd_locate(unsigned char x, unsigned char y){  lcd_writecommand(HD44780_DDRAM_SET | (x + (0x40 * y)));}  //-----------------------------------------------------------------------------void lcd_strxy(unsigned char * text, unsigned char x, unsigned char y){  lcd_locate(x,y);  while(*text)    lcd_writedata(*text++);}  //-----------------------------------------------------------------------------void lcd_writebinary(unsigned int var, unsigned char bitCount){  signed char i;   for(i = (bitCount - 1); i >= 0; i--)     {     lcd_writedata((var & (1 << i))?'1':'0');     }}  //-----------------------------------------------------------------------------void LCD_ShiftLeft(void){  lcd_writecommand(HD44780_DISPLAY_CURSOR_SHIFT | HD44780_SHIFT_LEFT | HD44780_SHIFT_DISPLAY);}  //-----------------------------------------------------------------------------void LCD_ShiftRight(void){  lcd_writecommand(HD44780_DISPLAY_CURSOR_SHIFT | HD44780_SHIFT_RIGHT | HD44780_SHIFT_DISPLAY);}  //-----------------------------------------------------------------------------void lcd_init(void){ volatile unsigned char i = 0; volatile unsigned int delayCnt = 0; RCC_APB2PeriphClockCmd(LCD_CLK_LINE, ENABLE); GPIO_InitStructure.GPIO_Pin = LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7|LCD_RS|LCD_RW|LCD_EN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(LCD_GPIO, &GPIO_InitStructure); GPIO_WriteBit(LCD_GPIO, LCD_RW | LCD_RS | LCD_EN, Bit_SET); udelay(200); GPIO_WriteBit(LCD_GPIO, LCD_RW | LCD_RS | LCD_EN, Bit_RESET); udelay(200); /* Initial by instruction */ lcd_writecommand(0x030); udelay(500); lcd_writecommand(0x030); udelay(200); lcd_writecommand(0x030); udelay(200); lcd_writecommand(HD44780_FUNCTION_SET |                HD44780_FONT5x7 |                HD44780_TWO_LINE |                HD44780_8_BIT); //0x38 udelay(200); lcd_writecommand(HD44780_DISPLAY_ONOFF |                HD44780_DISPLAY_OFF); //0x08 udelay(200); lcd_writecommand(HD44780_CLEAR); //0x01 udelay(200); lcd_writecommand(HD44780_ENTRY_MODE |                HD44780_EM_SHIFT_CURSOR |                HD44780_EM_INCREMENT);//0x06 udelay(200); lcd_writecommand(HD44780_DISPLAY_ONOFF |                HD44780_DISPLAY_ON |                HD44780_CURSOR_ON |                HD44780_CURSOR_NOBLINK);//0x0E udelay(200);}  //-----------------------------------------------------------------------------void lcd_addchar (unsigned char chrNum, unsigned char n, const unsigned char *p){        lcd_writecommand(HD44780_CGRAM_SET | chrNum * 8);        n *= 8;        do         lcd_writedata(*p++);        while (--n);}  //-----------------------------------------------------------------------------void lcd_cls(void){        lcd_writecommand(HD44780_CLEAR);}   unsigned char* intToStr(int n){ int i = 0; int j = 0; char *tmp = (char*)malloc(sizeof(char));    unsigned char *ret = (unsigned char*)malloc(12); if(n<0 || n>9){  *tmp = n%10+48;  n-=n%10;  n/=10;  tmp++;  i++; }  *tmp = n+48; i++; while(i--){   ret[j++] = *tmp--; } return ret;}void lcd_int(int a){  unsigned short ch,first; //you need this to display 0 if there was any char     //Get first char    ch = a/10000;    if(ch){     lcd_writedata(48+ch);     first = 1;    }     //Get second char    ch = (a/1000)%10;    if(ch || first){     lcd_writedata(48+ch);     first = 1;    }     //Get third char    ch = (a/100)%10;    if(ch || first){     lcd_writedata(48+ch);     first = 1;    }     //Get fourth char    ch = (a/10)%10;    if(ch || first){     lcd_writedata(48+ch);     //first = 1;                   //q    }     //Get fifth char    ch = a%10;    //if(ch || first)   //you dont need to check las one if ch is 0 then just display it, unless you dont want to then uncomment this line ("//q" line too)     lcd_writedata(48+ch);       // lcd_str(intToStr(n));} void lcd_intxy(int n, unsigned char x, unsigned char y){        lcd_locate(x,y);        lcd_int(n);}

lcd_hd44780.h

//******************************************************************************//    THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY.//    AUTHOR SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT//    OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING//    FROM USE OF THIS SOFTWARE.//****************************************************************************** //##############################################################################// lcd_hd44780.h//############################################################################## //****************************************************************************////#include "main.h"  #define LCD_GPIO GPIOB#define LCD_CLK_LINE RCC_APB2Periph_GPIOB #define LCD_D0 GPIO_Pin_0#define LCD_D1 GPIO_Pin_1#define LCD_D2 GPIO_Pin_5#define LCD_D3 GPIO_Pin_8#define LCD_D4 GPIO_Pin_9#define LCD_D5 GPIO_Pin_10#define LCD_D6 GPIO_Pin_11#define LCD_D7 GPIO_Pin_12 #define LCD_RS GPIO_Pin_13#define LCD_RW GPIO_Pin_14#define LCD_EN GPIO_Pin_15//******************************************************************************//  #define HD44780_CLEAR                                          0x01 #define HD44780_HOME                                           0x02 #define HD44780_ENTRY_MODE     0x04        #define HD44780_EM_SHIFT_CURSOR    0x00        #define HD44780_EM_SHIFT_DISPLAY   0x01        #define HD44780_EM_DECREMENT    0x00        #define HD44780_EM_INCREMENT    0x02 #define HD44780_DISPLAY_ONOFF    0x08        #define HD44780_DISPLAY_OFF     0x00        #define HD44780_DISPLAY_ON                  0x04        #define HD44780_CURSOR_OFF                  0x00        #define HD44780_CURSOR_ON                   0x02        #define HD44780_CURSOR_NOBLINK    0x00        #define HD44780_CURSOR_BLINK    0x01 #define HD44780_DISPLAY_CURSOR_SHIFT 0x10        #define HD44780_SHIFT_CURSOR               0        #define HD44780_SHIFT_DISPLAY              8        #define HD44780_SHIFT_LEFT                         0        #define HD44780_SHIFT_RIGHT                  4 #define HD44780_FUNCTION_SET    0x20        #define HD44780_FONT5x7      0x00        #define HD44780_FONT5x10     0x04        #define HD44780_ONE_LINE     0x00        #define HD44780_TWO_LINE     0x08        #define HD44780_4_BIT      0x00        #define HD44780_8_BIT      0x10 #define HD44780_CGRAM_SET                                    0x40 #define HD44780_DDRAM_SET                                    0x80 //##############################################################void lcd_init(void);void lcd_cls(void);void lcd_str(unsigned char * text);void lcd_strxy(unsigned char * text, unsigned char x, unsigned char y);void lcd_locate(unsigned char x, unsigned char y);void lcd_int(int n);void lcd_intxy(int n, unsigned char x, unsigned char y); //############################################################### void lcd_writedata(unsigned char dataToWrite);void lcd_writecommand(unsigned char commandToWrite);void lcd_writebinary(unsigned int var, unsigned char bitCount);void lcd_addchar (unsigned char chrNum, unsigned char n, const unsigned char *p);

main.c

lcd_init();         while (1)          {                   lcd_locate(1,0);                  lcd_str("Mazen");                  lcd_locate(7,0);                  lcd_str("A.");                  lcd_locate(0,1);                  lcd_str("-3125");           }

STM32 透過ADC_GetFlagStatus 知道 EOC狀態並讀值

其實網路隨意google一下就很多資料

uint16_t readADC1(void) {  uint16_t value;  //ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_55Cycles5); // Start the conversion  ADC_SoftwareStartConvCmd(ADC1, ENABLE);   // Wait until conversion completion  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);  ADC_ClearFlag(ADC1, ADC_FLAG_EOC); // Get the conversion value  value = ADC_GetConversionValue(ADC1);  ADC_SoftwareStartConvCmd(ADC1, DISABLE); return value;}
void AdcPro(void){ static uint16_t buf[SAMP_COUNT]; static uint8_t write; uint32_t sum; uint8_t i; //buf[write] = ADC_GetConversionValue(ADC1); 原本直接讀取資料   buf[write] = readADC1();  if (++write >= SAMP_COUNT) {  write = 0; } sum = 0; for (i = 0; i < SAMP_COUNT; i++) {  sum += buf[i]; } g_usAdcValue = sum / SAMP_COUNT; /* 取平均 */ //ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* 原本先為下次使用而enable */}

如何在部落格加入code 區域 (修改css)

可以在各種部落格裡面看到許多將程式碼加入文章裡

其實只要幾個步驟就可以完成了

也就是修改css, 將下面這一段加入CSS就好啦

pre { padding: 10px 5px 10px 22px; margin: 10px 15px; border: 1px solid #CCC; font:13px/120% 'Courier New'; letter-spacing: 0.07em; background: #F5F5F5 url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6r-beClagoumej1FnptO1ZkMGkgzGr5q86AlJhe4OQ15lEdwYy6lCIVyJbohqe4-QzLfwEeLJMJDbqKQX1UtZ3WGn1Gb3vGVOQfZruUU-kKdvWT4LQX8pjRPIFS_6TpAOHpYYqZlFAmg/s1600/code.gif) no-repeat scroll left top;  text-align: justify; overflow: auto; color:#333;}

完成後, 之後發表文章時
請記得在你要發布的程式碼加入 pre tag 如下:

<pre> 程式碼 </pre>

Google blogger 怎麼設定最新回應(留言)

最近搬家過來blogger 但是找不到簡單widget獲得最新留言 稍微做了一下功課, 可以透過RSS的方式去做

1. 看看網址 http://YOUR_BLOG_ADDRESS/feeds/comments/default
這個網址可以看到你部落格的最新回應RSS
像我的話, 就是 http://ezmm.blogspot.tw/feeds/comments/default

2.將此網址複製
http://YOUR_BLOG_ADDRESS/feeds/comments/default

3.加入資訊

選”資訊提供”, 再進去貼網址即可

—-