Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <intrinsics.h>
- #include<iostm8s003f3.h>
- #include<stdint.h>
- /**********************/
- /*define block*/
- #define SetBit(reg, bit) reg |= (1<<bit)
- #define ClearBit(reg, bit) reg &= (~(1<<bit))
- #define InvBit(reg, bit) reg ^= (1<<bit)
- #define BitIsSet(reg, bit) ((reg & (1<<bit)) != 0)
- #define BitIsClear(reg, bit) ((reg & (1<<bit)) == 0)
- /**********************/
- /*variable block*/
- uint8_t dev_addr;/*dev address for I2C*/
- /*************************/
- /*function declaration block*/
- static void clock_init(void);
- static void port_init(void);/*init port for module*/
- static void uart_init(void);/*init uart set*/
- static void uart_send(unsigned char data);
- __interrupt void UART1_RXE(void);
- /*static void i2c_init(void);*/
- /************************/
- /*function definition block*/
- static void clock_init(void){
- CLK_ICKR|=(1<<0);/*enable hight speed internal RC oscillator */
- CLK_CKDIVR|=(1<<4|1<<3|1<<2|1<<1|1<<0);/*enable RC prescale/1*/
- }
- static void port_init(void){
- PD_DDR|=(1<<5);/*UART TX as output*/
- PB_DDR|=(1<<5);/*SDA as output*/
- }
- static void uart_init(void){
- UART1_BRR2=0x03U;/*set baudrate 9600*/
- UART1_BRR1=0x68U;/*with 0.02% error*/
- UART1_CR2|=(1<<5);/*reciever interrupt enable*/
- UART1_CR2|=(1<<3);/*transmitter enable*/
- UART1_CR2|=(1<<2);/*reciever enable*/
- }
- /*uint8_t read_addr(void){
- return 0xff;
- }*/
- /*static void uart_send(unsigned char data){
- while(!UART1_SR_TXE){
- UART1_DR=data;
- }
- }*/
- int main(void){
- clock_init();
- port_init();
- uart_init();
- __enable_interrupt();
- PD_ODR|=(1<<3);
- while(1){
- /*uart_send(0xffU);*/
- PD_ODR^=(1<<3);
- }
- }
- __interrupt void UART1_RXE(void)
- {
- UART1_DR=UART1_DR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement