Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragmaconfig WDT = OFF
- #pragmaconfig OSC = HS
- #pragmaconfig FCMEN = OFF
- #pragmaconfig XINST = OFF
- #include <xc.h>
- #include<spi.h>
- #include<delays.h>
- #include <adc.h>
- #include <stdlib.h>
- #defineIODIRA_address 0x00
- #defineIODIRB_address 0x01
- #defineGPIOA_address 0x12
- #defineGPIOB_address 0x13
- #defineCS PORTAbits.RA2
- #define_XTAL_FREQ 4000000
- #defineLCD_clear 0b00000001
- #defineLCD_cursor_off 0b00001111
- #defineLCD_set 0b00111011
- #defineLCD_entry 0b00000110
- #definecoloana1_inc 128
- #definecoloana2_inc 192
- intvoltage=0;
- intvoltage2=0;
- floatvoltage1 =0.0;
- intconversie=0;
- unsigned charsir1[30],sir2[30];
- voidGPIO_set(charaddress,charvalue)
- {
- CS=0;
- WriteSPI1(0x40);
- WriteSPI1(address);
- WriteSPI1(value);
- CS=1;
- }
- voidIODIR_set(charaddress,chardir)
- {
- CS=0;
- WriteSPI1(0x40);
- WriteSPI1(address) ;
- WriteSPI1(dir);
- CS=1;
- }
- voidLCD_cmd(charc)
- {
- GPIO_set(GPIOA_address,0x00);
- __delay_ms(50);
- GPIO_set(GPIOB_address,c);
- __delay_ms(50);
- GPIO_set(GPIOA_address,0x40);
- __delay_ms(50);
- GPIO_set(GPIOA_address,0x00);
- __delay_ms(50);
- }
- voidLCD_init()
- {
- IODIR_set(IODIRA_address,0x00);
- IODIR_set(IODIRB_address,0x00);
- LCD_cmd(0b00111111);
- LCD_cmd(0b00001111);
- LCD_cmd(0b00000001);
- LCD_cmd(0b00000110);
- }
- voidLCD_poz(intcoloana, intlinie)
- {
- if(coloana==1)
- {
- LCD_cmd(coloana1_inc+linie);
- }
- if(coloana==2)
- {
- LCD_cmd(coloana2_inc+linie);
- }
- voidLCD_out(unsigned charlitera)
- {
- GPIO_set(GPIOA_address,0x80);
- __delay_ms(50);
- GPIO_set(GPIOB_address,litera);
- __delay_ms(50);
- GPIO_set(GPIOA_address,0xc0);
- __delay_ms(50);
- GPIO_set(GPIOA_address,0x00);
- __delay_ms(50);
- }
- voidLCD_out_text(unsigned char*s)
- {
- while(*s)
- LCD_out(*s++);
- }
- voidmain()
- {
- LATD = 0x00;
- TRISD = 0x00;
- while(1){
- for(inti=0;i<=20;i++)
- __delay_ms(20);
- TRISAbits.RA2=0;
- CS=1;
- OpenSPI1(SPI_FOSC_64,MODE_10,SMPEND);
- OpenADC(ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD, ADC_CH0 &
- ADC_REF_VDD_VSS & ADC_INT_OFF, 1);
- ConvertADC();
- while(BusyADC());
- LATD=ReadADC();
- voltage = (ReadADC()*5)/1024;
- voltage1 = (ReadADC()*5.0)/1024;
- voltage2=voltage1*100-voltage*100;
- CloseADC();
- itoa(sir1,voltage,10);
- itoa(sir2,voltage2,10);
- LCD_init();
- LCD_poz(2,5);
- LCD_out_text(sir1);
- LCD_out('.');
- LCD_out_text(sir2);
- CloseSPI1();}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement