Lesson 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

8

Binary
654321


00000000
00000001
00000010
00000011
00000100

.
11111111

255
25511111111

59



void main()
{ TRISB=0;
PORTB=0;delay_ms(1000);
Loop:
PORTB++;

Delay_ms(1000);

Goto loop;
}

TRISB=0;
PORTB=0;
portb++;
portb

portb=0;
00000000
portbportb++;
00000000
00000001

60


goto loop;
00000001portb

00000010
portb
00000011
binary
PORTB++
500

Loop:
PORTB=0B00000000;
Delay_ms(1000);
PORTB=0B00000001;
Delay_ms(1000);
PORTB=0B00000010;
Delay_ms(1000);
..

PORTB=0B11111111;
Delay_ms(1000);
Goto loop;

61

PORTB
PORTB=3;
PORTB=0B00000011;

62

9

b3,b2,b1,b0
1001

void main()
{ TRISB=0;
PORTB=0; delay_ms(1000);
while(1){

PORTB++;

delay_ms(1000);
if(portb==9) {portb=0; delay_ms(1000);}

}
goto looploop
5while(1)
if
portb portb

63



b7 b0
portb=0;trisb=0;

b0 while(1)
portb portb++
delay_ms(1000); b0
9 portb if
Portb
while if
b1 ( 10 2portb
if
11portbwhile
9 portb
if1001
portb portb=0; If
delay_ms(1000);
portbwhile

64


if for :
void main(){
char x;
TRISB=0; PORTB=0;
delay_ms(1000);
while(1){
for(x=0;x<9;x++){ PORTB++; delay_ms(1000);}
portb=0;delay_ms(1000);
}
}
for portb
forportbfor
portb

65

10


3 30 12 9 6 3
01


00000

00010

00110

01001
...
11110

30


void main()

char number; char x;


TRISB=0; PORTB=0;delay_ms(1000);
while (1) { for (x=1;x<=10;x++)

number=3*x;
portb=number;

delay_ms(1000);

portb=0; delay_ms(1000);
66

}
}



while(1)
x=1 for
10forx=10
number=3*x;
portb=number;

delay_ms(1000);

number x=1
number=3*x; 3
portb=number;
b1 b0
portb=3;portb=0b00000011;
delay_ms(1000);
6 3X2 number x=2
portb=number; portb 6 x=2 number=3*x;
xx=3
x<=10 11 x 10
portb=0 for for
fordelay_ms(1000)
forfor

67

12
15

18

21

24
27
30

char8portb
B7B0PORTB
number
void main()
{char x;
TRISB=0; PORTB=0;delay_ms(1000);
While (1) { for (x=1;x<=10;x++) { portb=3*x; delay_ms(1000); }
portb=0; delay_ms(1000);
}
}
8portb
B7B05
68

for



1 byte = 8 bitsbyte8 bits8
32 416
char 8
int 16 unsigned short

char

(byte)
1
1
1
1
2
2
4
4

signed char
short
unsigned short
int
unsigned
long
unsigned long

0 .. 255
- 128 .. 127
- 128 .. 127
0 .. 255
-32768 .. 32767
0 .. 65535
-2147483648 .. 2147483647
0 .. 4294967295

Type
float
double
long double

Size in bytes
4
4
4

Range
1.17549435082 * 10 .. 6.80564774407 * 1038
1.17549435082 * 10-38 .. 6.80564774407 * 1038
1.17549435082 * 10-38 .. 6.80564774407 * 1038
-38

2
69


8 char
25511111111
255char
255 255255
signed char
127 -128

32.66

ahmadchar
char ahmad;
for;
char x;
x8
x , y , z

Char x;
Char y;
Char z;
70



Char x,y,z;
,
void main()

71

11

7 segmetns seven segment







7 segment

72

common anode
datasheet

7447

73

12


portb++
portb
portb
void main()
{ TRISB=0;
PORTB=9; delay_ms(1000);
while(1){

PORTB--;

delay_ms(1000);
if(portb==0) {portb=9; delay_ms(1000);}

portb portb--;
9 portb
portb--;89
if portb
9if
74











delay_ms(1000);

void main()
{ TRISB=0;
PORTB=9;
while(1){ delay_ms(1000);


}

PORTB--;

if(portb==0) { delay_ms(1000); portb=9;}


75


delay_ms(1000);

76


void main()
{char x; TRISB=0;
portb=9;
while(1){
for(x=10;x>0;x--)
{
delay_ms(1000);
portb--;
}
portb=9;
}
}

X
X


77



void main()

{ TRISB=0;

while(1){
for(PORTB=9;PORTB>0;PORTB--)

delay_ms(1000);

}
}
}

PORTB
portbchar portb
porta
1
for
for(PORTB=9;PORTB>=0;PORTB--)


for
portb=9 for
8 for
portb Portb--
7
78


Portb--
portb
forPortb
char portb
255
255portb
for
255portb 255
254 portb for
255
7447

255portb

79


void main()

{ TRISB=0;

while(1){

for(PORTB=9;PORTB>=0;PORTB--)
{

delay_ms(1000);

if(portb==0) portb=10;


if 255 portb
portb-- portb=10
9 portb
10
portb=10




80


void main()

{ TRISB=0;

while(1){


for(PORTB=9;PORTB>0;PORTB--)
{
delay_ms(1000);
}

9 9
if
for
portb=9
8
1 portb
whileforfor
portb for for

81

for

void main()
{ TRISB=0;

while(1){


for(PORTB=9;PORTB>0;PORTB--)

delay_ms(1000);
}

delay_ms(1000);
}

forportb

while(1)





82

13

26 24

void main()
{ TRISB=0;portb=2;
while(1){
delay_ms(1000);
portb++;
portb++;
if (portb==8){ delay_ms(1000);portb=2;}
}
}
83


portb++

for for

Portb2
portb=portb+2;

2Portb
90Portb
portb=portb+90;

void main()

{ TRISB=0;portb=2;

while(1){
delay_ms(1000);
portb=portb+2;
if (portb==8){ delay_ms(1000);portb=2;}
}
}

84


portbporta=3;

portb=porta+2;
2portaportb
Portaportb
portb=portb+2; 3
portb Portb
portb Portb
2Portb
portb=portb+1portb++
portb
x=x+6 x

85

14

28





Portb=portb+2
portb=portb-2
void main()
{ TRISB=0;portb=8;
while(1){
delay_ms(1000);
portb=portb-2;
if (portb==2){ delay_ms(1000);portb=8;}
}
}

86


portb=portb-2
portb-=2;
portb=portb+2
Portb+=2;
portb=portb*5;5
Portb*=5

mm
yy 12350
10
mm=(350+12-yy)/10;

10
mm=350+12-yy/10;

10 yy


87

15

if

if(porta.f0==0) { }
if(porta.f1==0) { }
88

portb++ portb
portb

portb portb-- portb

portb-- portb++

89



void main()
{
TRISB=0; TRISA=0XFF;
PORTB=0;
while(1){

if(porta.f0==0) { portb++; delay_ms(500);}


if(porta.f1==0){portb--; delay_ms(500);}

}
}
MCLR




active lowMCLR
MCLR

MCLRrestart

MCLR
90








push buttonMCLR

MCLR
5MCLR

portb
portb MCLR
portb=0;
MCLR
A2
if(porta.f2==0){portb=0; delay_ms(500);}
91

16


90







5
5

92


void main()

{
TRISB=0; TRISA=0XFF;

PORTB=0;

while(1){

if(porta.f0==0) {

portb++;

if(portb==10) portb=0;

delay_ms(500);

if(porta.f1==0) {
portb--;

}
}

if(portb==255) portb=9;

delay_ms(500);


93


portb++portbif
portbif
if(portb==10) portb=0;
delay_ms(500); if
portb++ portb
ifportb++delay_ms(500);
)

portb A1
255255

255 portb-- Portb


255Portb

if(portb==255) portb=9;

portb--if
portbportb--255portb

if(portb==0) portb=9;
portb--;
94

if(porta.f1==0) A1
portb portb
portb--
8
8

95

if(porta.f1==0) {
if(portb==0) portb=10;

portb--;

delay_ms(500);

A1 portb
portb--portb

255portbA0if
Ifportb++
if(porta.f0==0) {
if(portb==9) portb=255;
portb++;
delay_ms(500);

}
if(porta.f1==0) {
if(portb==0) portb=10;
portb--;
delay_ms(500);
}


96

You might also like