CPP 74
Mycode Guest on 3rd October 2024 05:23:59 PM
  1.  
  2. #include <mega32a.h>
  3.  
  4. // Alphanumeric LCD functions
  5. #include <alcd.h>
  6. #include <delay.h>
  7.  
  8. typedef struct {
  9.                     unsigned char pa_dir;
  10.                     unsigned char pb_dir;
  11.                     unsigned char pc_dir;
  12.                     unsigned char pd_dir;
  13.                     ////////////////////////////
  14.                     unsigned char pa_val;
  15.                     unsigned char pb_val;
  16.                     unsigned char pc_val;
  17.                     unsigned char pd_val;} gpio_ss;
  18.  
  19.  
  20. gpio_ss pins;
  21.  
  22. void gpio_init (gpio_ss *x)
  23. {
  24.  DDRA = x -> pa_dir;
  25.  DDRB = x -> pb_dir;
  26.  DDRC = x -> pc_dir;
  27.  DDRD = x -> pd_dir;  
  28.  
  29.  PORTA = x -> pa_val;
  30.  PORTB = x -> pb_val;
  31.  PORTC = x -> pc_val;
  32.  PORTD = x -> pd_val;
  33.  
  34. }
  35.  
  36. void set_port(char p_name, unsigned char p_value){
  37.  switch(p_name)  {
  38.     case 'A':
  39.         PORTA=p_value;
  40.     break;
  41.     case 'B':
  42.         PORTB=p_value;
  43.     break;
  44.     case 'C':
  45.         PORTC=p_value;
  46.     break;
  47.     case 'D':
  48.         PORTD=p_value;
  49.     break;
  50.  
  51.    }
  52.  
  53.  
  54. }
  55.  
  56. #define In 0x00
  57. #define Out 0xff
  58.                    
  59.  
  60. void main(void)
  61. {
  62.     pins.pa_dir=Out;
  63.    
  64.    
  65.     gpio_init(&pins);
  66.  
  67. while (1)
  68.       {  
  69.         set_port('A',0xff);  
  70.         delay_ms(500);
  71.         set_port('A',0x00);
  72.         delay_ms(500);
  73.  
  74.  
  75.       }
  76. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.