Konversi program C ke Bahasa Majelis Online
gcc –S program.cpp
Shy Salamander
gcc –S program.cpp
#define_XTAL_FREQ 4000000
#include <htc.h>
#include <stdint.h>
#define IN1 RD0
void PWM_Init();
void PWM_Set_DCycle(uint16_t);
void ADC_Init();
uint16_t ADC_Citire();
unsigned char v,a;
void main(void)
{
TRISA =0b00000001;
ANSEL= 0b00000001;
ANSELH=0;
ADCON0= 0b10000001;
ADCON1=0b00000000;
TRISD =0;
PWM_Init();
ADC_Init();
while(1){
PWM_Set_DCycle(ADC_Citire()); // setam PWM duty cycle dupa rezultatul citit de la RA0
__delay_ms(1);
}
}
void PWM_Init(){
// VOM folosi portul CCP2 pentru iesire asa ca il vom initializa pentru PWM
CCP2M3=1;
CCP2M2=1;
PR2=124; // setam frecventa pentru PWM
TMR2IF=0;
T2CKPS1=1; // Prescaler (1_16), astfel încât valoarea „124” să fie corectă
TMR2ON=1;
while(!TMR2IF);
TRISC=0; //i nitializam pinul de iesire
}
void PWM_Set_DCycle(uint16_t DC){
// se verifica daca este in intervalul de 10 biti
if(DC<=1023){
CCP2Y=DC & 1;
CCP2X=(DC&2)>>1;
CCPR2L=(DC>>3) & (0b001111111);
}
}
void ADC_Init(){ // initializare ADC
ADCS1=1;
ADCS0=0;
VCFG0=0;
VCFG1=0;
CHS3=0;
CHS2=0;
CHS1=0;
CHS0=0;
ADFM=1;
ADON=1;
}
uint16_t ADC_Citire(){ //citeste valoarea potentiometrului
__delay_us(11);
GO_nDONE=1; // incepe conversia
while(GO_nDONE);
return((ADRESH<<8) + ADRESL);
}
int main()
{
int size, i, A[50], B[50];
int add[10], mul[10], mod [10];
float div[10];
printf("enter array size: \n");
scanf("%d", &size);
printf("enter elements of 1st array: \n");
for(i=0; i < size; i++)
{
scanf("%d", &A[i]);
}
printf("enter the elements of 2nd array: \n");
for(i=0; i < size; i++)
{
scanf("%d", &B[i]);
}
for(i=0; i < size; i++)
{
add [i]= A[i]+B[i];
mul[i]= A[i] * B[i];
div [i]= A[i] / B[i];
mod [i]= A[i] % B[i];
}
printf("\nadd, \nsub, \n mul, \ndiv, \nmod \n");
printf("--------------------\n");
for(i=0; i <size; i++) {
printf("\n%d\t", add[i]);
printf("%d\t", mul[i]);
printf("%.2f\t", div[i]);
printf("%d\t", mod[i]);
}
return 0;
}
//You must always define the 'main()' function, as it is an execution entry point
int main() {
int s1,s2,s3;
printf("Enter the triangle 3 sides");
scanf("%d %d %d",&s1,&s2,&s3);
if(s1+s2>s3)&&(s2+s3>s1)&&(s3+s1>s2){
printf("It is a valid triangle");
}
else{
printf("It is an invalid triangle");
}
return 0;
}
int main() {
int s1,s2,s3;
printf("Enter the triangle 3 sides");
scanf("%d %d %d",&s1,&s2,&s3);
if(s1+s2>s3)&&(s2+s3>s1)&&(s3+s1>s2){
printf("It is a valid triangle");
}
else{
printf("It is an invalid triangle");
}
return 0;
}
Interface 4x4 matrix keyboard to 8051. Write ALP to display the
ASCII value of pressed key on P2.
if(a>b){
c=0;
}
else {
c=1;
}
#include <stdio.h>
void affichage (int tab []) {
int i ;
for (i = 0 ; i < 10 ; i = i + 1) {
printf ("%d ", tab [i]) ;
}
printf ("\n") ;
}
int main () {
int tab [10] ; /* un tableau de 10 entiers est initialisee */
int i ;
/* On demande a l’utilisateur de remplir les 10 cases du tableau */
for (i = 0 ; i < 10 ; i = i + 1) {
printf ("Quelle valeur pour la case %d ?\n", i) ;
scanf ("%d", &tab [i]) ;
}
affichage (tab) ;
return 0 ;
#include <stdio.h>
#include <conio.h>
sum(int,int,int);
void main()
{
int a,b,c,d;
clrscr();
printf("\nACCEPT VALUE FOR a,b,c:\n");
scanf("%d %d %d",&a,&b,&c);
d=sum(a,b,c);
printf("\nSUM OF %d,%d and %d IS %d",a,b,c,d);
getch();
}
sum(int x,int y,int z)
{
int temp;
temp=x+y+z;
return(temp);
}