Skip to main content

Control Unit (CodevisionAVR)

  1. #include <mega8515.h>
  2. //8MHz CB1 final 29 April without pulse strecher
  3. #include<stdio.h>                        
  4. #include<delay.h>
  5. // Declare your global variables here
  6.        char a;    
  7.        bit dlag,ulag;
  8.        char str[16];  
  9.        int dly=0;  
  10.        
  11. void blink();    
  12. void blink2();    
  13. void main(void)
  14. {
  15. DDRB=0xFF;
  16. DDRC=0x80;
  17. PORTC=0x00;
  18. ACSR=0x80;    
  19.     while (1)
  20.       {
  21.      
  22.       a=PINC;    
  23.       a^=0x70;    
  24.            
  25.    if(a&0x20)       {PORTB=0x02;    blink2();    
  26.           }    
  27.    
  28.    else if(a&0x40)  {PORTB=0x01;    blink2();    
  29.          }
  30.    else if(a&0x10)  {PORTB=0x00;    blink2();  
  31.             }
  32.    else
  33.    {  
  34.        if(a)
  35.        {
  36.         switch(a)
  37.             {
  38.             case 1: //Move Down  
  39.                     PORTB=0x06;;  
  40.                     delay_ms(200);
  41.                     dly=0;
  42.            
  43.                  break;    
  44.                  
  45.             case 3: //Move Down Sort Steps
  46.                     PORTB=0x06;    
  47.                     delay_ms(100);    
  48.                     dly=0;
  49.                        
  50.                   break;  
  51.                  
  52.              ////////////////////////////////////
  53.                  
  54.                      
  55.             case 2: //Move Down Long Steps          
  56.             if(ulag)
  57.             {
  58.              delay_ms(250); ulag=0;
  59.             }
  60.             else
  61.             {        PORTB=0x06;    
  62.                     delay_ms(35);    
  63.                     dly=15;   dlag=1;
  64.              }      
  65.                   break;                  
  66.             /////////////////////////////////
  67.             case 6: //Don't move
  68.                           PORTB=0x08;    delay_ms(200);  
  69.                               dly=10;       ulag=0; dlag=0;
  70.                    break;
  71.             ///////////////////////////////////////////      
  72.             case 4: //Move Up in Steps    
  73.             if(dlag)
  74.             { delay_ms(250); dlag=0;
  75.             }
  76.             else
  77.             {                        
  78.                              PORTB=0x11;     delay_ms(35);  
  79.                                dly=15; ulag=1;
  80.              }                  
  81.                     break;
  82.              
  83.              ////////////////////////////////////////////
  84.                                                                                    
  85.                          
  86.                              
  87.             case 12: //Move Up in Short steps
  88.                                PORTB=0x11;      delay_ms(90);  
  89.                                   dly=0;
  90.                      break;          
  91.             case 8:  //Move Up in Long Steps  
  92.                                 PORTB=0x11;     delay_ms(190);
  93.                                     dly=0;
  94.             //Long or Short steps is controlled by the time delay
  95.             }
  96.        
  97.        }
  98.        else
  99.        {
  100.        //Make all OFF
  101.        PORTB=0;
  102.        delay_ms(dly);
  103.        }                                      
  104.    
  105.        }    
  106.        
  107.        
  108.       };    
  109. }
  110.    void blink()
  111. {  
  112. a&=0x0F;
  113. switch(a)
  114.             {
  115.             case 1: //Move Down  
  116.                     PORTB=0x04;;  
  117.                     delay_ms(200);
  118.                     dly=0;
  119.            
  120.                  break;    
  121.                  
  122.             case 3: //Move Down Sort Steps
  123.                     PORTB=0x04;    
  124.                     delay_ms(100);    
  125.                     dly=0;
  126.                        
  127.                   break;  
  128.                  
  129.              //////////////////////////////////////////
  130.                  
  131.                      
  132.             case 2: //Move Down Long Steps          
  133.                PORTB=0x04;    
  134.                     delay_ms(50);    
  135.                     dly=15;  
  136.                   break;                  
  137.             ///////////////////////////////////
  138.             case 6: //Don't move
  139.                           PORTB=0x08;    delay_ms(80);  
  140.                               dly=10;  
  141.                    break;
  142.             ///////////////////////////////////
  143.             case 4: //Move Up in Steps    
  144.                              
  145.                              PORTB=0x10;     delay_ms(50);  
  146.                
  147.                     break;
  148.                  
  149.              //////////////////////////////////
  150.                          
  151.             case 12: //Move Up in Short steps
  152.                                PORTB=0x10;      delay_ms(90);  
  153.                                   dly=0;
  154.                      break;          
  155.             case 8:  //Move Up in Long Steps  
  156.                                 PORTB=0x10;     delay_ms(190);
  157.                                     dly=0;
  158.             //Long or Short steps is controlled by the time delay
  159.             }
  160. }                            
  161.       void blink2()
  162. {  
  163. a&=0x0F;
  164. switch(a)
  165.             {
  166.             case 1: //Move Down  
  167.                     PORTB.2=1;  
  168.                     delay_ms(200);
  169.                     dly=0;
  170.            
  171.                  break;    
  172.                  
  173.             case 3: //Move Down Sort Steps
  174.                     PORTB.2=1;    
  175.                     delay_ms(100);    
  176.                     dly=0;
  177.                        
  178.                   break;  
  179.                  
  180.              /////////////////////////////////
  181.                  
  182.                      
  183.             case 2: //Move Down Long Steps          
  184.                PORTB.2=1;    
  185.                     delay_ms(50);    
  186.                     dly=15;  
  187.                   break;                  
  188.             ////////////////////////////////
  189.             case 6: //Don't move
  190.                           PORTB.3=1;    delay_ms(80);  
  191.                               dly=10;  
  192.                    break;
  193.             /////////////////////////////////////
  194.             case 4: //Move Up in Steps    
  195.                              
  196.                              PORTB.4=1;     delay_ms(50);  
  197.                
  198.                     break;
  199.                
  200.              ////////////////////////////////////
  201.                                                                                    
  202.                          
  203.                              
  204.             case 12: //Move Up in Short steps
  205.                                PORTB.4=1;      delay_ms(90);  
  206.                                   dly=0;
  207.                      break;          
  208.             case 8:  //Move Up in Long Steps  
  209.                                 PORTB.4=1;     delay_ms(190);
  210.                                     dly=0;
  211.             //Long or Short steps is controlled by the time delay
  212.             }
  213. }                            

Comments

Popular posts from this blog

Questions

1. What is a Stub function? Ans : A function without any definition which presents no error when called. 2. Why there are two ld scripts generated by STM32Cube IDE? Ans: The CubeIDE always presents two different LDscripts on for generating the executable for Debugging which goes to RAM another for normal code upload that goes to flash memory. 3. What is Supervisory Mode/ privileged mode ? Ans : When you are using a Kernel then there are two modes user mode and privileged mode. In User mode the applications cant have system calls. 4. What is "make -j6" ? Ans : Make has an argument for number of jobs, so when you add -j6 it will create 6 different compiler instances, so that the systems could use multicore to the fullest.  Linux people generally do add "-j $(nproc)" where nproc is a command line which returns number of processors attached. 5. What is weak attribute ? Ans : Weak attribute used to denote weak symbols which helps linkers to choose one function out of mul...

#@$%

  #include  "msp430x21x2.h"     #define PWM_OUTPUT              0x03 #define DUTY_CYCLE              TA0CCR2 #define MAX_LIMIT               300   /* #define no_of_samples           1 #define duty_cycle_limit        1000 #define temp_sensor             0xA000   #define panel_selection_cutoff  250 */ #define PV_VOLTAGE              INCH_0 #define PV_CURRENT              INCH_1 #define BATT_VOLTAGE            INCH_2 #define BATT_CURRENT            INCH_3   #define UPPER_CRG_LVL           0x0105 // 0x00FF // 0x00F5 //0x023A #define LOWER_CRG_LVL   ...

STM32 Port configuration via structures

 How Does STM32CubeIDE   /*Configure GPIO pin : Pd3 */   GPIO_InitStruct.Pin = GPIO_PIN_3;   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;   GPIO_InitStruct.Pull = GPIO_NOPULL;   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;   HAL_GPIO_Init(GPIOd, &GPIO_InitStruct);  Now what is GPIOD and GPIO_InitStruct GPIOD the definition is deep inside CMSIS "Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f411xe.h" #define GPIOD               ((GPIO_TypeDef *) GPIOD_BASE) and  GPIOD_BASE declared in same file #define GPIOD_BASE            (AHB1PERIPH_BASE + 0x0C00UL) Now GPIO_InitStruct is comes from  the line GPIO_InitTypeDef GPIO_InitStruct = {0};  so the structure GPIO_InitTypeDef is as follows as defined in  typedef struct {   uint32_t Pin; /*!< Specifies the GPIO pins to be configured.     This parameter can be any value of @ref GPIO_p...