Chapter Programming in C

Slides:



Advertisements
Similar presentations
1 生物計算期末作業 暨南大學資訊工程系 2003/05/13. 2 compare f1 f2  只比較兩個檔案 f1 與 f2 ,比完後將結果輸出。 compare directory  以兩兩比對的方式,比對一個目錄下所有檔案的相 似程度。  將相似度很高的檔案做成報表輸出,報表中至少要.
Advertisements

Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
第七章 抽樣與抽樣分配 蒐集統計資料最常見的方式是抽查。這 牽涉到兩個問題: 抽出的樣本是否具有代表性?是否能反應出母體的特徵?
Reference, primitive, call by XXX 必也正名乎 誌謝 : 部份文字取於前輩 TAHO 的文章.
期末專題 - 吊人頭遊戲 第 35 組 組員 : 電機系 49841XXXX XXX 電機系 49841OOOO OOO.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
: Boxes ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11003: Boxes 解題者:蔡欣燁 解題日期: 2007 年 3 月 19 日.
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
Chapter 2 聯立線性方程式與矩陣 緒言 線性方程式組 (systems of linear equations) 出現 在多數線性模式 (linear model) 中。根據以往解 題的經驗,讀者們也許已發現方程式的解僅與 該方程式的係數有關,求解的過程也僅與係數 的運算有關,只要係數間的相關位置不改變,
Chapter 3 Growth of Functions Asymptotic notation Θ-notation: f(n) = Θ(g(n)) , g(n) is an asymptotically tight bound for f(n) 。 Θ(g(n)) = {f(n)|
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
JAVA 程式設計與資料結構 第十章 GUI Introdution III. File Chooser  File Chooser 是一個選擇檔案的圖形介面, 無論我們是要存檔還是要開啟檔案,使 用這個物件都會讓我們覺得容易且舒適。
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
論文研討 2 學分 授課教師:吳俊概.
組員 : 林士恆 許嘉宏 不可計算函數 不可計算函數 根據 12.2 的 Church-Turing 命題,當我們找到一個杜林不 可計算的函數時,一般就相信它是個不可計算的函數。 簡單來說,就是一個計算超出今日電腦能力的函數。
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
3-3 使用幾何繪圖工具 Flash 的幾何繪圖工具包括線段工具 (Line Tool) 、橢圓形工具 (Oval Tool) 、多邊星形 工具 (Rectangle Tool) 3 種。這些工具畫出 來的幾何圖形包括了筆畫線條和填色區域, 將它們適當地組合加上有技巧地變形與配 色, 不但比鉛筆工具簡單,
Matlab Assignment Due Assignment 兩個 matlab 程式 : Eigenface : Eigenvector 和 eigenvalue 的應用. Fractal : Affine transform( rotation, translation,
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
: Little Red Riding Hood ★★★☆☆ 題組: Contest Volumes Archive with Online Judge 題號: 11067: Little Red Riding Hood 解題者:陳明凱 解題日期: 2008 年 3 月 14 日 題意:
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
Chapter 7 Logic Instructions and Programs
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
: A-Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10930: A-Sequence 解題者:陳盈村 解題日期: 2008 年 5 月 30 日 題意: A-Sequence 需符合以下的條件, 1 ≤ a.
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/25 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH 2.4~CH 2.6 &
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
: Flip Sort ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10327: Flip Sort 解題者:歐子揚 解題日期: 2010 年 2 月 26 日 題意:在這個問題中使用一種排序方式 (Flip) ,意思就是 只能交換相鄰的.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Linguistics phonetic symbols. 先下載 IPA 字型檔案,執行安裝。 由於這個程式的字型目錄設定錯誤, 所以等重新開機時就會發現字型消失。 所以必須根據以下步驟來讓 Windows 加入 IPA 字型。
Learning Method in Multilingual Speech Recognition Author : Hui Lin, Li Deng, Jasha Droppo Professor: 陳嘉平 Reporter: 許峰閤.
Chapter 10 m-way 搜尋樹與B-Tree
JAVA 程式設計與資料結構 第十六章 Hash Tables. Introduction Hash Tables 結構為一個 Array ,稱之為 Bucket array 。 如果想要新增一個物件,要根據這個物件的特性 將其加入 Hash Table 內。 Bucket Array 用 A 來代替,其.
組合語言與系統程式 軟體使用教學(中文詳細版).
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
: Dream ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11414: Dream 解題者:李育賢 解題日期: 2008 年 9 月 2 日 題意: 題目會給你一個數字代表測資的數量 ( 最多 100 組 ) , 每組測資第一個數字是此圖形點的個數.
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
第 6 章 迴圈結構 6-1 計數迴圈 6-1 計數迴圈 6-2 條件迴圈 6-2 條件迴圈 6-3 巢狀迴圈 6-3 巢狀迴圈 6-4 While/End While 迴圈 6-4 While/End While 迴圈 6-5 跳出迴圈 6-5 跳出迴圈 6-6 VB.NET 的錯誤處理 6-6 VB.NET.
連續隨機變數 連續變數:時間、分數、重量、……
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/30 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH7.1~CH /12/26.
:Stupid Sequence ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11319: Stupid Sequence 解題者:李育賢 解題日期: 2008 年 11 月 23 日 題意: 一個公式 f(x)=a 0 +a 1 x+a.
: Wine trading in Gergovia ★★☆☆☆ 題組: Contest Volumes with Online Judge 題號: 11054: Wine trading in Gergovia 解題者:劉洙愷 解題日期: 2008 年 2 月 29 日 題意:在 Gergovia.
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
函式 Function 東海大學物理系‧資訊教育 施奇廷. 函式簡介 當程式越來越大、越複雜時,程式的維護、 除錯會變得更困難,此時必須引入函式來 簡化程式或將程式分段,將程式重複的部 分改寫為函式,將程式「模組化」 這種作法有下列優點:節省程式發展的時 間、邏輯容易瞭解、程式容易除錯、可分 工合作完成程式.
資料結構實習-六.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
C 語言練習題 2010/12/2. C 程式的格式 一、 C 程式的格式 (1). /* …. */ 是 C 程式的 ______ main() 的內容是由敘述構成的 (2). 敘述要以 __ 為結束符號 (3). 變數、函數都要做 ____ 的宣告 (4). ‘=’ 是 ____ 用的算符 (5).
What is static? CS340100, NTHU Yoshi. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1;
:Count the Trees ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10007:Count the Trees 解題者:楊家豪 解題日期: 2006 年 3 月 題意: 給 n 個點, 每一個點有自己的 Label,
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
:Rings and Glue ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10301: Rings and Glue 解題者:施博修 解題日期: 2011 年 5 月 18 日 題意:小約翰有了個大麻煩,他不小心將 rings.
舊式廚房大搜查 土木三甲 黃雅琳 D 這是大家最常看見的 ” 灶爐 ”! 要砍一大堆的木材來起火 ! 才能飽餐一頓 ~ 現在都使用瓦斯來代替燃燒木材了 ! 所以算是 “ 改良過的造爐 ”!
幼兒行為觀察與記錄 第八章 事件取樣法.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
Presentation transcript:

Chapter 7 8051 Programming in C

Objective 8051只有64K bytes的 ROM,當程式轉成hex file後不能超過64K bytes。如果使用C語言來寫8051的程式,轉成hex file通常都會比使用組合語言寫的hex file來得大。然而用C語言來寫8051的程式,還是有許多的優點。因此這一章我們將簡單的介紹C語言的指令。並且從現在開始,每一個章節會同時使用C語言和組合語言來介紹8051。 當然 8051程式還是要小於64K,所以瞭解8051 C的資料結構,使code大小符合要求是很重要的。

Sections 7.1 Data types and time delay in 8051 C 7.2 I/O programming in 8051 C 7.3 Logic operations in 8051 C 7.4 Data conversion programs in 8051 C 7.5 Accessing code ROM space in 8051 C 7.6 Data serialization using 8051 C

Why Program the 8051 in C It is easier and less time consuming to write in C than Assembly. C is easier to modify and update. You can use code available in function libraries. C code is portable to other microcontrollers with little or no modification.

Translation between C and Assembly A for-loop in C int z; for (z=255; z>0; z--) P1=z; A loop in Assembly MOV R2,#255 ABC: MOV P1,R2 DJNZ R2,ABC

Section 7.1 Data Types and Time Delay in 8051 C

Re-examine C Data Type Understanding the data types of C can help programmers to write an efficient code. We will focus on (See Table7-1) unsigned char, signed char unsigned int, signed int, Single bit: sbit (sfr) , bit (bit-addressable RAM) Special function register: sfr C compiler will allocate a RAM space for your variables (char, int & bit).

Table 7-1. Some Widely Used Data Types for 8051 C

Unsigned Char The most widely used data types for the 8051 8-bit data type The range of unsigned char: 0-255 (00-FFH) When do you use unsigned char? To set counter value (Example 7-1) The string of ASCII character (Example 7-2) For toggling ports (Example 7-3) unsigned char 雖然稱為 character, 但可當做 unsigned integer 來用, 尤其當數字不大時 (0-255), 會比 unsigned integer 來得節省空間. 如果不加上 unsigned, 內定是 signed 的格式

Signed Char 8-bit data type 2’s complement representation The range of unsigned char: -128-127 (00-FFH) When do you use signed char? To present a given quantity such as temperature

Example 7-1 (unsigned char) Write an 8051 C program to send values 00-FF to port P1. Solution: #include <reg51.h> void main(void) { unsigned char z; for (z=0; z<=255; z++) P1=z; } sdcc 不認識 <reg51.h>, 要換成 <8051.h>

Example 7-2 (unsigned char) Write an 8051 C program to send hex values for ASCII characters of 0,1,2,3,4,5,A,B,C, and D to port P1. Solution: #include <reg51.h> void main(void){ unsigned char mynum[]=“012345ABCD”; unsigned char z; for (z=0; z<10; z++) P1=mynum[z]; } Note: “012345ABCD” is stored in RAM and can be changed. sdcc 不認識 unsigned char;

Example 7-3 (unsigned char) Write an 8051 C program to toggle all the bits of P1 continuously. Solution: #include <reg51.h> void main(void) { for ( ; ; ) { //repeat forever P1=0x55; //0x: in hex (binary) P1=0xAA; }

Example 7-4 (signed char) Write an 8051 C program to send values of -4 to 4 to port P1. Solution: #include <reg51.h> void main(void) { char mynum[]={+1,-1,+2,-2,+3,-3,+4,-4}; unsigned char z; for (z=0; z<8; z++) P1=mynum[z]; }

Integer 16-bit data type The range of unsigned int: 0-65535 The range of signed int: -32,768-32,767 Since the 8051 is an 8-bit microcontroller and the int data type takes two bytes of RAM, we must not used the int data type unless we have to. You should try to use unsigned char instead on int.

Example 7-5 (unsigned int, sbit) Write an 8051 C program to toggle bit D0 of P1 50,000 times. Solution: #include <reg51.h> sbit MYBIT=P1^0; void main(void) { unsigned int z; for (z=0;z<50000;z++) { MYBIT=0; MYBIT=1; }

Time Delay Three factors that can affect the accuracy of the time delay: Crystal frequency of 8051 system 8051 machine cycle timing Compiler used for 8051 C

Example 7-6 (time delay) Write an 8051 C program to toggle bits of P1 continuously forever with some delay. Solution: #include <reg51.h> void main(void) { unsigned int x; for (;;) { P1=0x55; for (x=0;x<40000;x++); //time delay P1=0xAA; for (x=0;x<40000;x++); }}

Example 7-7 (1/2) Write an 8051 C program to toggle bits of P1 continuously with a 250 ms delay. Solution: #include <reg51.h> void MSDelay(unsigned int); void main(void) { while(1) { //repeat forever P1=0x55; MSDelay(250); //time delay P1=0xAA; MSDelay(250) }}

Example 7-7 (2/2) Assume the program is tested for the DS89C420 with XTML=11.0592MHz. 90ns 1275 = 114750ns  1ms void MSDelay(unsigned int itime) { unsigned int i,j; for (i=0; i<itime; i++) for (j=0; j<1275; j++); // 1ms delay }

Section 7.2 I/O programming in 8051 C

Access SFR Way to access SFR and single bit of SFR Use name of SFR and reg51.h #include <reg51.h> P1=0x55; //P1=55H reg51. h is necessary. See Example 7-1. Use the sfr data type and declare by yourself sfr P1 = 0x90; reg51. h is not necessary.

Access Single Bit of SFR Way to access a single bit of SFR Use sbit and name of SFR #include <reg51.h> sbit MYBIT = P1^5; //D5 of P1 See Example 7-5. Use sbit to declare the bit of SFR and declare by yourself sbit MYBIT = 0x95; //D5 of P1 reg51. h is not necessary. See Example 7-17.

Example 7-16 (1/2) (sfr) Write an 8051 C program to toggle all the bit of P0, P1 and P2 continuously with a 250 ms time dealy. Solution (a): sfr P0 = 0x80; // declare by yourself sfr P1 = 0x90; // declare by yourself sfr P2 = 0xA0; // declare by yourself void MSDelay(unsigned int); // MSDelay is as same as one in // Example7-1. Ignored it here.

Example 7-16 (2/2) (sfr) void main(void) { unsigned int z; while(1) { //repeat forever P0=0x55; P1=0x55; P2=0x55; MSDelay(250); //time delay P0=0xAA; P1=0xAA; P2=0xAA; } }

Example 7-17 (sbit) Write an 8051 C program to turn bit P1.5 on and off 50,000 times. Solution (a): sbit MYBIT = 0x95; // P1^5 void main(void) { unsigned int z; for (z=0;z<50000;z++) { MYBIT=1; MYBIT=0; } } This program is similar to Example 7-5.

Access Bit-addressable RAM You can use bit to access one bit of bit-addressable section of the data RAM space 20H-2FH. #include <reg51.h> sbit inbit = P1^0; bit membit; //C compiler assign a RAM space for mybit membit = inbit; //Read P1^0 to RAM See Example 7-18.

Example 7-18 (bit) Write an 8051 C program to get the status of bit P1.0, save it, and send it to P2.7 continuously. Solution: #include <reg51.h> sbit inbit = P1^0; sbit outbit = P2^7; bit membit; void main(void) { while(1) { //repeat forever membit = inbit; outbit = membit }}

Section 7.3 Logic operations in 8051 C

Bit-wise Operations in C AND & 0x35 & 0x0F = 0x05 OR | 0x04 | 0x68 = 0x6C Exclusive-OR ^ 0x54 ^ 0x78 = 0x2C Inverter ~ ~0x55 = 0xAA 0011 0101 AND 0000 1111 0000 0101 0000 0100 OR 0110 1000 0110 1100 0101 0100 XOR 0111 1000 0010 1100 NOT 0101 0101 0000 0101

Bit-wise Shift Operation in C Shift Right >> 0x9A >> 3 = 0x13 shift right 3 times 0x77 >> 4 = 0x07 shift right 4 times Shift Left << 0x96 << 4 = 0x60 shift left 4 times 1001 1010  0001 0011 0111 0111  0000 0111 1001 0110  0110 0000

Table 7-3. Bit-wise Logic Operations for C

Example 7-19 Run the following program on your simulator and examine the results. Solution: #include <reg51.h> void main(void) { P0=0x35 & 0x0F; P0=0x04 | 0x68; P0=0x54 ^ 0x78; P0=~0x35; P0=0x9A >> 3; P0=0x77 >> 4; P0=0x96 << 4; }

Section 7.4 Data conversion programs in 8051 C

Data Conversion Packed BCD to ASCII conversion See Example 7-24 ASCII to packed BCD conversion See Example 7-25 Checksum byte in ROM See Example 7-29 (using +) Binary to decimal and ASCII conversion in C See Example 7-26, 27, 28 ( using /, %) Look the content by yourself

Table 7-4. ASCII Code for Digits 0-9

Section 7.5 Accessing code ROM space in 8051 C

To Store Data We have three spaces to store data: 1. the 128 bytes RAM space with address range 00-7FH If you declare variables (ex: char) to store data, C compiler will allocate a RAM space for these variable. 2. Use code space External code memory (64K) + on-chip ROM (64K) Data is embedded to code or is separated as a data section 3. External data memory for data RAM or ROM see Chapter 14

Data Stored in RAM Where are the variables assigned by C compiler? 8051 C compiler allocates RAM locations for variables in the following order: Bank 0: addresses 0-7 Individual variables: addresses 08H and beyond Array elements: addresses right after variables Array size is limited in 128 bytes RAM. Stack: address right after array elements Check your simulation tool

8052 RAM Space 8052 has 256 bytes RAM. Based on 8052 architecture, you should Use the reg52.h header file. Choose the 8052 option when compiling the program.

Using ROM to Store Data To make C compiler use the code space (on-chip ROM) instead of RAM space, we can put the keyword “code” in front of the variable declaration. unsigned char mydata[] = “HELLO” HELLO is saved in RAM. code unsigned char mydata[] = “HELLO” HELLO is saved in ROM. See Example 7-33

Example 7-33 (1/3) Compare and contrast the following programs and discuss the advantages and disadvantages of each one. Solution (a): #include <reg51.h> void main(void) { P1=“H”; P1=“E”; P1=“L”; P1=“L”; P1=“O”; } Data is embedded into code. Simple, short, not flexible.

Example 7-33 (2/3) Solution (b): #include <reg51.h> void main(void) { unsigned char mydata[]=“HELLO”; unsigned char z; for (z=0; z<5; z++) P1 = mydata[z]; } Data is stored in RAM and does not occupied ROM.

Example 7-33 (3/3) Solution (c): #include <reg51.h> void main(void) { code unsigned char mydata[]=“HELLO”; unsigned char z; for (z=0; z<5; z++) P1 = mydata[z]; } Data is stored in ROM. However, data and code are separate.

Section 7.6 Data serialization using 8051 C

Serializing Data Two ways to transfer a byte of data: 1. Using the serial port. For PC. See Chapter 10. 2. To transfer data one bit a time and control the sequence of data and spaces in between them. For LCD, ADC, ROM Example 7-34

Example 7-34 Write a C program to send out the value 44H serially one bit at a time via P1.0. The LSB should go out first. Solution: #include <reg51.h> sbit P1b0 = P1^0; sbit regALSB = ACC^0; void main(void) { unsigned char conbyte = 0x44; unsigned char x; ACC = conbyte; for (x=0; x<8; x++) { P1b0 = regALSB; ACC = ACC >> 1; } } ACC P1.0 D7 D0

You are able to Examine the C data type for the 8051 Code 8051 C program for time delay and I/O operations Code 8051 C program for I/O bit manipulation Code 8051 C program for logic and arithmetic operations Code 8051 C program for ASCII and BCD data conversion Code 8051 C program for binary (hex) to decimal conversion Code 8051 C program to use the 8051 code space Code 8051 C program for data serialization