aLec31_pointers - Introduction to Embedded Microcomputer...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Embedded Microcomputer Systems Lecture 31.1 Jonathan W. Valvano Use of stack for temporary calculations Pointers in C Linked List FIFO Linked structures F S M Trees short n; // value -32768 to +32767 short m; // value -32768 to +32767 short *p; // address 0x0000 to 0xFFFF char c; // value -128 to +127 char d; // value -128 to +127 char *s; // address 0x0000 to 0xFFFF char name[8] = “valvano”; Pointer assignments p = &n; // p points to n s = &c; // s points to c Pointer dereferencing *p = 5000; // n = 5000 *s = 60; // c = 60 m = *p; // m = n (which is 5000) d = *s; // d = c (which is 60) More pointer assignments s = name; // s points to name or s = &name[0]; // s points to name Fixed offset pointer dereferencing c = *s; // c = ‘V’ d = s[1]; // d = ‘a’ Static Linked list circular output pattern Structure defines the format of each entry Putting the const causes it to be stored in ROM lots of ROM fixed values initialized when code burned into ROM No const causes it to be stored in RAM Just some RAM variable values/pointers initialized at run time each time system is powered up must have an initialization copy in ROM const struct node { unsigned char data; // output value const struct State *next; // links }; typedef const struct node nodeType; nodeType *Pt; Linked list definition nodeType LL[4]={ {5, &LL[1]}, {6, &LL[2]}, {10,&LL[3]}, {9, &LL[0]}}; Pointer initialization Pt = LL; or Pt = &LL[0]; Pt 5 61 09
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Embedded Microcomputer Systems Lecture 31.2 Jonathan W. Valvano Output all four values to port T void OutputAll(void){ nodeType *p; p = Pt; do{ PTT = p->data; // fetch value from list p = p->next; while(p != Pt); } Output one value to port T each interrupt Pointer initialization Pt = LL; Execute ISR every 1 ms void interrupt 8 OC0ISR(void){ PTT = Pt->data; // fetch value from list Pt = Pt->next; TC0 = TC0 + 1000; // 1000 means 1ms TFLG1 = 0x01; // acknowledge } Stepper motor controller Inputs: Go and Turn Outputs: two 4-wire bipolar stepper motors Bipolar stepper motor interface using an L293 driver // Port M bits 1-0 are inputs // =00 Stop // = 10 Go (55,66,AA,99) // = 01 RTurn(55,69,AA,96) // = 11 LTurn(55,96,AA,69) // Port T bits 7-0 are outputs to steppers S55 $55 01 S66 $66 01 SAA $AA 01 S99 $99 01 00 S69 $69 S96 $96 11 00 00 01 01 10 10 10 10 10 10 const struct State { unsigned char out; // command const struct State *next[4];}; typedef const struct State StateType; StateType *Pt; #define S55 &fsm[0] #define S66 &fsm[1]
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

aLec31_pointers - Introduction to Embedded Microcomputer...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online