EN0
Member
Hey Everyone,
I'm having a little trouble with my switch-case statement code.
First I had this:
Now I have this:
For some reason the latter code doesn't work! Any noticeable errors? I'm using C18 with PIC18F1320.
Thanks,
Austin
I'm having a little trouble with my switch-case statement code.
First I had this:
Code:
104. while(1)
105. {
106. if(!PORTAbits.RA1) // Switch 1
107. {
108. LATB = 0x01; //LED 1
109. playSong(0);
110. }
111. else if(!PORTAbits.RA2) // Switch 2
112. {
113. LATB = 0x02; // LED 2
114. playSong(1);
115. }
116. else if(!PORTAbits.RA3) // Switch 3
117. {
118. LATB = 0x04; // LED 3
119. playSong(2);
120. }
121. else
122. {
123. LATB = 0x08; // Otherwise, LED 4
124. }
125. }
Now I have this:
Code:
1.while(1)
2.{
3. switch(PORTA)
4. {
5. case 0x0D:
6. {
7. LATB = 0x01;
8. playSong(0);
9. break;
10. }
11. case 0x0B:
12. {
13. LATB 0x02;
14. playSong(1);
15. break;
16. }
17. case 0x07:
18. {
19. LATB = 0x04;
20. playSong(2);
21. break;
22. }
23. default:
24. {
25. 0x08;
26. }
27. }
28.}
For some reason the latter code doesn't work! Any noticeable errors? I'm using C18 with PIC18F1320.
Thanks,
Austin