fork download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. typedef struct {
  4. unsigned int led1:1;
  5. unsigned int led2:2;
  6. unsigned int led3:3;
  7. unsigned int led4:4;
  8. } PortR;
  9. void set_led_stute (PortR* register_prt, int led_num, int state) {
  10. if(led_num==1) {
  11. register_prt->led1=state;
  12. } else if(led_num==2) {
  13. register_prt->led2=state;
  14. } else if(led_num==3) {
  15. register_prt->led2=state;
  16. } else if(led_num==4) {
  17. register_prt->led2=state;
  18. }
  19. }
  20. int main() {
  21. PortR vr_register={0};
  22. PortR*port_register=&vr_register;
  23. for(int i=1; i<=4; ++i) {
  24. printf("Включение светодиода %d\n", i);
  25. sleep(1);
  26. set_led_stute(port_register,i,0);
  27. printf("Выключение светодиода");
  28. sleep(1);
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Включение светодиода 1
Выключение светодиодаВключение светодиода 2
Выключение светодиодаВключение светодиода 3
Выключение светодиодаВключение светодиода 4
Выключение светодиода