C 向左移动一次并从进位中获取值
我使用的是带C编译器的微芯片版本v8.63 下面的一段代码,我想‘值1206420333240d移位一次’,我知道进位寄存器中有1位。但是我不知道如何用汇编语言为pic18F4550检索这些值。 我的问题是,如何使用汇编程序对PIC18F4550进行一次移位,并从进位中获取值 包括整个项目C 向左移动一次并从进位中获取值,c,assembly,microcontroller,C,Assembly,Microcontroller,我使用的是带C编译器的微芯片版本v8.63 下面的一段代码,我想‘值1206420333240d移位一次’,我知道进位寄存器中有1位。但是我不知道如何用汇编语言为pic18F4550检索这些值。 我的问题是,如何使用汇编程序对PIC18F4550进行一次移位,并从进位中获取值 包括整个项目 unsigned int rood = 1206420333240; void main (void) { //int rood[] = {0,0,1,0,1,0,1,0,1,0,1,1,1
unsigned int rood = 1206420333240;
void main (void)
{
//int rood[] = {0,0,1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1};
TRISD = 0x00; // PORTD als output
TRISB = 0b00110000; // RB4 en RB5 als input
TRISA = 0x00; // RA output
RCONbits.IPEN = 0; // prioriteit disable
INTCONbits.GIE = 1; // enable interrupt
INTCONbits.RBIE = 1; // interrupt portB on
while(1)
{
_asm sleep _endasm
}
}
#pragma interrupt ISR
void ISR (void)
{
if (INTCONbits.RBIF==1)
{
if(PORTBbits.RB5==0) // S3 pressed ?
{
int i = 0;
int b;
do {
// Try to shift left (SHF) and get value in carry.
_asm
mov EAX, 1206420333240d
_endasm
//LATAbits.LATA2 = rood << 1;
//LATDbits.LATD1 ^= 1;
//do-while for the frequentie (1500 is de freq)
b = 0;
do {
b++;
}while(b <= 2000);
i++;
}while(sizeof(rood) <= 50);
//LATDbits.LATD1 ^= 1; // D2 togglen
}
}
INTCONbits.RBIF = 0;
}
无符号整数rood=1206420333240;
真空总管(真空)
{
//int rood[]={0,0,1,0,1,0,1,0,1,1,0,0,0,1,1,0,1,0,0,1,0,1,0,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1};
TRISD=0x00;//端口D als输出
TRISB=0B0011000;//RB4 en RB5 als输入
TRISA=0x00;//RA输出
RCONbits.IPEN=0;//优先级禁用
INTCONbits.GIE=1;//启用中断
INTCONbits.RBIE=1;//打开中断端口B
而(1)
{
_asm睡眠_endasm
}
}
#pragma中断
无效ISR(无效)
{
if(INTCONbits.RBIF==1)
{
如果(PORTBbits.RB5==0)//S3被按下?
{
int i=0;
int b;
做{
//尝试左移(SHF)并在进位中获取值。
_asm
mov EAX,1206420333240d
_收尾
//LATAbits.LATA2=rood如果使用,则有一个命令将向左旋转一个值,并将进位存储在指定寄存器中
RLCF REG, 0, 0
(参见上述链接文档中的第243页)。注意:您必须查询进位寄存器以检索值,并可能将最低有效位设置为“0”,以抵消旋转操作,并将其转换为移位操作
您可以借助内联汇编来执行此操作,但是,我想知道为什么以下操作不起作用:
int carry = (value & 0X80) >> 7; // substitute the correct bit masks here
value = value << 1;
if( carry == 1 )
{
// Perform action
}
int carry=(值&0X80)>>7;//在此处替换正确的位掩码
value=value在实践中可能不起作用,因为我使用的所有PIC C编译器都是一派胡言。我相信你的判断……我可以自由地承认,我所做的唯一PIC18开发是在汇编程序中,所以我不完全确定C在这里能工作得有多好。