
كود:
char m ;
char tens=0,ones=0,speed=0;
char number[]={'x',' ','9','8','7','x','6','5','4','x','3','2','1','x','x','0','x'};
char number2[]={'x',' ',9,8,7,'x',6,5,4,'x',3,2,1,'x','x',0,'x'};
void main() {
Keypad_Init(&PORTD);
Lcd_Init(&PORTB); // Initialize LCD on PORTb
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off
lcd_out(1,1,"Enter the " );
lcd_out(2,5," duty");
loop:
m=keypad_read();
if(m==0) {goto loop;}
else if(m==14){goto loop;}
else if(m==16){Lcd_Cmd(Lcd_Clear);portd=0xF0;goto loop;}
else {Lcd_Cmd(Lcd_Clear);tens=(number2[m]*10)*2.55;lcd_chr_cp(number[m]);delay_ms(500);}
test2: //testing the second pushing down
m=keypad_read();
if(m==0) {goto test2;}
else if(m==16){Lcd_Cmd(Lcd_Clear);portd=0xF0;goto loop;}
else {ones=number2[m];lcd_chr_cp(number[m]);delay_ms(500);}
speed=tens+ones ;
test3: //tes ng the third pushing down
m=keypad_read();
if(m==0) {goto test3;}
else if(m==14){Lcd_Cmd(Lcd_Clear);portd=0xF0;}
else {goto test3;}
// initialize PWM1 module
PWM1_Init(5000);
PWM1_Start();
// set new PWM1 pattern ratio,
PWM1_Change_Duty(speed);
lcd_out(1,1,"speed");
lcd_chr_cp(number[m] );
}
النتيجة
1

2

3
المشاكل بعد هذا التعديل
. لا استطيع تغير الدوتي مرة اخري يبقي البرنامج كما في الصورة رقم3