HomeTOOLSEXAMPLESEXPLORE EMBEDDEDE CSERVICESECU SAMPLESRegistration
Embedded C programming Tutorial , Keil C ide , microsoftware.gr
Keil CRC and CAN BUS codes.
1. Shift led left
2.It's time for DAVE! <7/6/13>
3.Capture/Compare unit 6
4.ASC0-GPT1-MACROS
5.ASC0-FIFO-PEC
6.Analog converter
7.Memory manipulation routines
8. Recursion
9.Understanding interrupt priorities using CAPCOM2 module
10. POINTERS TO FUNCTION <4/7/13>,<4/28/13>
11.Memory models, memory types
12. The heap , part 1
13. The heap , part 2
14. The heap , part 3
15. Structure example
16. Nested structures, Array of structures.
17. Passing array of structures to function using pointers.<1/5/13>
18. Self Referential Structures
19. BITFIELDS
20. Linked list example
21. Circular linked list
22. Union example
23. Enumeration example
24. Watchdog timer example
25. Void pointer example <7/4/13>
26. The sieve of Eratosthenes
27. The stack
28. Union and bitfields as flags example. <6/23/13>
29. Look up table example. <8/11/13>
30. Seven segment display multiplexing -four digits with dot- example
31. LCD character display example - JHD162A
32. Hash table introduction example <8/27/14>
33. Array of Linked Lists example
34. Array of Linked lists-more functions included.
35. Hash table construction,searching and printing.
36. Fininte state machines- a first approach.
37. Finite state machines- two events example.
38. SPI port and an AT25128 serial eeprom hardware.
39. CRC CHECK
40. Definite Integral Calculator for Scientists, Engineers...
41 .Hamming distance of a CRC polynomial
42. Linux play starting.
43. Galois GF(2^4) Finite Field
44. Construct your own time triggered real time operating system.
45. CANBUS C CODE EXAMPLE.
37. Finite state machines- two events example.

Finite state machine-two external events.

When the external event is event 0 the machine blinks the led_0.
When the external event is event 1 the  machine blinks the led_1.

The heart of the program is the enumeration:

typedef enum {    Led_0_off=0,  Uart_0_on=1, Led_0_on=2, Uart_0_off=3 , Led_1_off=0,  Uart_1_on=1, Led_1_on=2, Uart_1_off=3  }      state; 

and a 2x4 multidimensional array of structures :

action_and_next_state ar[2][4]=   {

                /*first line*/       {  {Uart_0_on , led_0_on} , {Led_0_on, uart_0_off}, {Uart_0_off, led_0_off}, { Led_0_off , uart_0_on} } , \
          
    /*SECOND LINE*/   {  {Uart_1_on , led_1_on} , {Led_1_on, uart_1_off}, {Uart_1_off, led_1_off}, { Led_1_off , uart_1_on} }


structures are of type:

typedef struct s{

state next;
action todo;
}action_and_next_state;  

and   typedef void  (*action)();
                                  
 

When event 0 was happened the machine follows the actions
  {Uart_0_on , led_0_on} , {Led_0_on, uart_0_off}, {Uart_0_off, led_0_off}, { Led_0_off , uart_0_on}

When event 1 was happened the machine follows the  actions:
{Uart_1_on , led_1_on} , {Led_1_on, uart_1_off}, {Uart_1_off, led_1_off}, { Led_1_off , uart_1_on} .

The machine sends messages and at Hyperterminal as in article No 36. 

The function that calculates the next state using the above enumeration is the:

 void statecalculation(event)
 {           
 
 stateevaluation= ar[event][courent ];  // action_and_next_state stateevaluation;
 courent= stateevaluation.next;

 (stateevaluation).todo();

 }               


initial courent state=0 


Function pointers refreshing :

http://denniskubes.com/2013/03/22/basics-of-function-pointers-in-c/


The C code and result.


 

Home|TOOLS|EXAMPLES|EXPLORE EMBEDDEDE C|SERVICES|ECU SAMPLES|Registration