2 Basics of C Flashcards

1
Q

The structure that both ASM and C share?

A
  • Configuration bits
  • Variable storage
  • Entry Point
  • Ininite loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

STRUC: What are the configuration bits?

A

These configure the basic setup of the PIC including things like the oscillator type and the presence of the watch dog timer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

STRUC: What is variable storage setup?

A

Definitions of variables, including where in memory to store them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

STRUC: Entry point

A

An indicator of where in the code the program counter will start

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

STRUC: Infinite loop?

A

An infinite loop is commonly used to keep repeating a set of operations ad infinitum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Config(Role/Default): FOSC?

A

The type of oscillator to use (external/internal/crystal)

Default: XT(external crystal)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Config(Role/Defult): WDTE?

A

Enable/Disable the watch dog timer

OFF(no wdt)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Config(Role/Defult): PWRITE?

A

Enable/Disable the power-up timer (72 ms)

ON(power-up timer)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Config(Role/Defult): CP?

A

Enable/Disable code protection

OFF(code protection)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Configuration bits for LED flash?

A

pragma config FOSC = XT // XT oscillator

// Setup configuration bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Configure oscillator frequency for flashing LED?

A

define _XTAL_FREQ 4000000

// Oscillator Frequency (4 MHz)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Flashing LED: Code to import library functions?

A

include

// Include C library functions for PIC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Flashing LED: Code to write to ports?

A

PORTBbits.RB0 = 1; // Set RB0 high __delay_ms(500); // Wait 0.5 seconds PORTBbits.RB0 = 0; // Set RB0 low __delay_ms(500); // Wait 0.5 seconds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Flashing LED: Port Setup?

A

// Set all port B bits to be output

TRISB = 0x0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Flashing LED: Main loop for the program?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A statement?

A

A statement is the smallest standalone element of a program, normally a single line of code

17
Q

In C a statement must be terminated with a ….

A

semicolon

18
Q

C: Blocks?

A

Statements can be grouped together into blocks, for example blocks of code that form part of a loop

19
Q

C: Example of a block?

A
20
Q

Advantages of C in terms of I/O?

A

We can read or write to individual pins as well as to the entire PORT register (this is a bit more powerful than ASM)

21
Q

Example in C of writing to a port?

A
22
Q

C program to Toggle an LED based on a user keypress

A
23
Q

Differences between ASM and C in variable naming?

A
  • In assembler we had to specify exactly where in memory a variable would live, this was tedious and does not port well to other PICs
  • In C life is much better, and all we need to do is give our variables a name and a type, for our small PIC we will only use integers
24
Q

Creating variables in C?

A
25
Q

C: Restrictions on variable names?

A
  • Just like in assembler, you must declare variables before you use them e.g int age;
  • Otherwise, the compiler doesn’t know what they are!
  • Variable names can contain letters (a-z, A-Z), digits (0-9) and underscores ( _ )
  • They must start with a letter or an underscore (but not a digit)
  • C keywords are not allowed e.g. if for do int . . .
26
Q
A