Académique Documents
Professionnel Documents
Culture Documents
Chapter 2 bates c
3/16/2014
1.c
Quiz
main()
RD1,RD0
{
int outbyte;
00
again: outbyte = 0;
01
while(1)
{
10
output_C(outbyte);
delay_ms(10);
11
outbyte ++ ;
if (!input(PIN_D0)) continue;
if (!input(PIN_D1)) break;
delay_ms(100);
if (outbyte == 100) goto again; }
output_c(255); }
3/16/2014
OUTPUT ON PORTC
UP COUNTER 0-255
10 msec delay
FF & sleep
UP COUNTER 0-255
10 msec delay
UP COUNTER 0-99
110 msec delay
RD1,RD0
if( input(PIN_d1))
{
output_b(outbyte2 & 0xf0);
delay_ms(100);
}
else
{
output_b(outbyte2);
delay_ms(100);
}
}
}
3/16/2014
OUTPUT ON PORTB
00
FF
01
10
F0 is displayed
11
void main()
{
int8 inbits;
while(1)
{
inbits = input_D();
switch(inbits)
{
case 1: output_C(1);
break;
case 2: output_C(3);
break;
case 3: output_C(7);
break;
default:output_C(0);
}}}
3/16/2014
2.c
Switch..Case
7.c
#include "16F877A.H"
If the switches read 0 then
porb counts from 3 to- 11
#use delay(clock=4000000)
main() {
If the switches read 1 then
porb counts from 6 to- 22
int x;
for(x=3;x<12; x++)
{
switch(input_D())
{
case 0:output_B(X);delay_ms(10); break;
case 1:output_B(2*x);delay_ms(10);break;
}
}
3/16/2014
prepared by :Maher Al-omari
output_B(17); }
3.c
#include "16F877A.H"
#use delay(clock=4000000)
1.
How many times will the program read
main()
portd? 3
{
2.
What will PORTB =to if PORTD is =127? 0x18
int x;
3.
What will PORTB =to if PORTD is =01? 01
for(x=3;x<=5; ++x)
{
switch(input_d())
{ case 128:output_b(0xF0); break;
case 1:output_b(input_d()); break;
case 2:output_high(PIN_b0); break;
default:output_b(0x18); }
}
}
3/16/2014
global variables
Start of function block,no (;)
call out()
goto $
prepared by :Maher Al-omari
void main() {
cnt=0;
while (TRUE)
{
if (!input_state(pin_D0))
cycle_forward ();
else
cycle_backward ();
}
}
4.c
main()
//// Main block
{
count = 2000; // Set variable value
out();
// Call function
while(1);
// Wait for reset
}
3/16/2014
3/16/2014
5.c
main()
{
count = 50000;
out(count); //
output_C(outbyte); // returned value
while(1);
}
prepared by :Maher Al-omari
output_b(outbyte);
}
}
The output on portb =5*count
3/16/2014