Upload
bridie
View
120
Download
3
Embed Size (px)
DESCRIPTION
PSOC_C 基本指令. 中州技術學院 電子系 副教授 余文俊. C 語言程式架構. 1. 主程式。 2. 函式 ( 副程式 ) 3. 標頭檔。. #include “stdio.h” void main(void) { unsigned char i, j, k; j=i+j; delay(); } void delay(void) { unsigned char i; for(i=1; i
Citation preview
PSOC_C
C1.
2. ( )
3.
#include stdio.hvoid main(void) { unsigned char i, j, k; j=i+j; delay(); }
void delay(void) { unsigned char i; for(i=1; i
()
\ / * ? < >| & + = [ ] %`
C1.0 0119
2.0 9213
3.0x 0x11161117
4. AA0x41 000x30 ##5. ( )
ASCII\00x00 (null space) NULL\a0x07 (bell ring) BELL\b0x08 (backspace) BS\t0x09 (tab) HT\n0x0a (newline) LF\f0x0c (form feed) FF\r0x0d (earriage return) CR\"0x22 (double quote) , "\'0x2c (singal quote) , '\\0x5c (bacrk slash) , \
C: int i 1. (A ~ Z) 2. (a ~ z) 3._
1. (A ~ Z) 2. (a ~ z) 3. (0 ~ 9) 4._
autobreakcasecharcontinue defaultdo double elseenumexternfloat gotoifintlongregister returnshortsizeofstaticstructswitchtypebefunionunsignedvoidwhile (?)
( ): 1.
char 8int 16float 32double32
2.
signed unsignedshort shortshortlong 2
C
m8c.inc
:
1 . char i; i
2 . char i , j , k =10; unsigned char i=A ;
( )(1) (local variable)
(2) (global variable)
(3) (external variable)
(local variable)void main(void){ char i; i=10; test();}
void test(void){ char i, k; i=100; k=i+k;}ii, kimain()i
(global variable) (*.c )A.C:B.C:char delay; void dkk (void)void main(void){{delay=10;} char delay ; delay delay = delay /10 }void f1 (void) {delay = delay+1;}
(external VARIABLE)A.C: B.C:EXTERNAL char delay; void dkk (void)void main(void) {char delay ; delay{delay=10;} delay = delay /10 }void f1 (void) {delay = delay+1;}
1.auto ( )2 . static ( )4.bit ( )
IAR-CR0R7(8051)auto ( )void delay (void){ auto char i; char i;}
static ( ) IAR-C IAR-C8051CPU00H7FH static char i static int j
C (statement): =char a, b, c, j ;a=3+2 ; a=5b=a+4 ; b=9c=a/b ; c=0j=a-b ; -4
10
** ** 10
** (bit)
C1. for 2. while 3. do_while 4. if else 5. switch case 6. goto ()
for
for(1) for() ; JMP $
(2) char i; for(i=0i
while:while (){ A ; } B ;:
(1)AB
(2){ }
(3)for( )
(4)
(1) (a) while (1); (b) while (1) { ; }(2) char i=100 ; while (i > 0) { i ; }(3)n char i=100; while (i > 0) 100 { ; i; } char i=3; while (i>0) { P1=i; i ; } (1)i=3 , P1=3 , i=2 (i )(2)i=2 , P1=2 , i=1 (i )(3)i=1 , P1=1 , i=0 (i )(4)
dowhile: do { A;} while () { B;}: (1) do A while doAB
(2){ } (3)for( ) (4)
ifelse(1)if{ }else{ } (2)else if () if () { A} { A} else C { B} C[][](1)if{ }else{ }AACBBC(2)if { }AACAC(3){ }(4)for( ) (5)
[] char i , j; j=0; i=0; if(i>5){j=j+10;} else {j=j+1; } i=33;
[] (1)j=0 , i=0 (2)i=33, j=1
switch _ case[] switch () { case 11 break case 22 break . case NN; break defaultN+1break break }A[](1)C 1 N default(2)switch(3)default
[]char c , k;c=10;switch (c) { case 2k=20; break; case 5k=50; break; case 8k=80; break; case 10k=100; break; case 12k=120; break; defaultk=255; break; }c=88[](1)c=10case 10 k=100switch case (2)c=88[break] 1.switchcasecase 2.for , if else , while , do-while
[] char i=0; for (; ;) { i=i+1; if (i= =10) { break} } i=10 for
[1]
[2]
[3]
(3)
[]
(1) []={12}
int total[3]={00,03,05} ;total[0]=0total[1]=3total[2]=5char iso[ ]={1, 2, 5, 10, 16} ; iso [0]=1iso [1]=2iso [2]=5iso [3]=10iso [4]=16char money [5] ; [1]5 money[0] , money[1] , money[2] , money[3] , money[4] [2] (char)
(a)
[m] [n]
char money [3] [2]; money32=6 6 money [0] [0] money [0] [1] money [1] [0] money [1] [1] money [2] [0] money [2] [1](b)
[m] [n] ={12 }
char car[2] [2]={1,2,3,4} car [0] [0]=1 car [0] [1]=2 car [1] [0]=3 car [1] [1]=4
(3)
(pointer)[1]
[2]
[3]
[4]C
*
char * ipip (char)
int * kkkk & *[1] & : [2]* :
i1000
char * ip;ip =&i; ip=1000
char i=10 , temp
char *ip /* ip */ip=& i /* ipi*/temp=*ip/* tempip i temp=i=10 */
()[] int ytr [4]={5, 4, 3, 2}ytr ( 5) * i=ytr[3]i=2*
int ytr[5], i, *ip; ip=&yrr[0]; yrr& P1=*ip ;P2=yrr[0]==>P1=P2=5
()char TAB[5]char ptrptr=&TAB[0]int datal [5]char *ptrptr=& datal [0]char TAB [ ]={1,4,5,7,9}char *ptrptr = &TAB[0]
(structure)[1][1] [2] ( )
[2] struct struct student a1
a1 student [3](A)typedef struct people { char child char adult char man char women int total }struct people china /* chinapeople */chinachild= 1 /* chinachild=1 */chinawomen=10; /* china women=10 */
(enum)[1] (enum) [2][3] ( ) 0 , 1 , 2 , , n1 :enum {012}enum colors {blue, red, green}blue=0 , red=1 , green=2
2
eunm {1=xx , 2=yy, } xx, yyenum today {hot=5 , rainny=10 , warm=20 , sunny=18}today hot=5, rainny=10, warm=20, sunny=183 enum {1=xx,2,3,} xx 2=xx+1, 3 =xx+2,
enum var {red=5 , green , blue , yan}red=5 , green=6 , blue=7 , yan=8
(union)
[1] [2] [3] [4] union {1,2,}
union {char i, char j, int k, char l} , i , j , k , l ,2 byte (int)
[]union {char money, int total}money=100/* money=100 */total=10000/* total=10000, money100 */
PSOC I/OPRT0DR8 bits8051 P0PRT1DR8 bits8051P1PRT2DR8 bits8051P2Example :outputPRT0DR=0x36; // P0=00110110
Example :inputunsigned char hh;hh=PRT0DR; // hh=P0