wikara gunawan / Mbed 2 deprecated DALI_TX_BACKWARDS_KL25Z

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Backward FRAME Code to debug
00002 
00003 #include "mbed.h"
00004 
00005 #define BROADCAST   0x00
00006 #define OFF         0x01
00007 #define ON          0x02
00008 
00009 #define TE 834/2 //Halftime of The Transmitted BIT
00010 
00011 DigitalOut myled(LED1);
00012 DigitalOut dali(D7);
00013 DigitalOut dali_tx(D8);
00014 
00015 
00016 int man_packets[20];
00017 int address;
00018 int command;
00019 int packet_fin;
00020 
00021 //How To initialise the interrupt
00022 
00023 void dali_packet(int address, int command){
00024     int i;
00025     int ones;
00026     //Start Bits 1
00027     man_packets[0] = 1;
00028     man_packets[1] = 0;
00029     man_packets[2] = 1;
00030     //Stop Bits
00031     
00032     for(i=0; i<8; i++){
00033         //For Address Conversion
00034         ones = address >> 7 - i;   //Shift the bit to the left   
00035         ones &= 0x01;
00036         if(ones == 1){
00037             man_packets[(i*2)+3] = 0;
00038             man_packets[(i*2)+4] = 1;
00039         } else {
00040             man_packets[(i*2)+3] = 1;
00041             man_packets[(i*2)+4] = 0;
00042         }
00043         
00044     man_packets[19] = 1;           //This is only a workaround solution
00045     }
00046 }
00047 
00048 
00049 int main() {
00050     while(1) {
00051         int i;
00052         dali = 1; 
00053         
00054         int value;
00055         printf("Enter an integer: ");
00056         scanf("%d", &value); 
00057 
00058         dali_packet(value, value+20);   //Process packets
00059         
00060         for(i=0; i<20; i++){
00061             dali =  man_packets[i];
00062             dali_tx = man_packets[i];
00063             wait_us(416);
00064             }
00065         dali = 1;
00066         dali_tx = 1;
00067         packet_fin = 1;   
00068         }
00069 }